Forked from Sunil02kumar/gist:396b9ec81b59a23aee29e5ca41a28202
Last active
November 6, 2022 14:07
-
-
Save mhamzas/1d6b4c26f39676fe4867e7425edac702 to your computer and use it in GitHub Desktop.
Find All Content Version Ids from Library and Generate File download URLs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string LibraryName='Demo Download Library'; | |
ContentWorkspace ws = [SELECT Id, RootContentFolderId FROM ContentWorkspace WHERE Name = :LibraryName LIMIT 1]; | |
Set<string> fileNameList = new Set<string>(); | |
List<ContentDocumentLink> filesToDelete= new List<ContentDocumentLink>(); | |
string csvString=''; | |
String domainUrl=URL.getSalesforceBaseUrl().toExternalForm(); | |
for(ContentDocumentLink con:[select id,LinkedEntityId,ContentDocumentId ,ContentDocument.LatestPublishedVersion.Title from ContentDocumentLink where LinkedEntityId=:ws.Id]){ | |
csvString = csvString +domainUrl+'/sfc/servlet.shepherd/version/download/'+con.ContentDocument.LatestPublishedVersionId+'\n'; | |
} | |
string instanceURL= URL.getSalesforceBaseUrl().gethost(); | |
Messaging.EmailFileAttachment csvAttc = new Messaging.EmailFileAttachment(); | |
blob csvBlob = Blob.valueOf(csvString); | |
string csvname= instanceURL +':'+LibraryName+'-Files download URL.csv'; | |
csvAttc.setFileName(csvname); | |
csvAttc.setBody(csvBlob); | |
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); | |
String[] toAddresses = new String[] {UserInfo.getUserEmail()}; | |
mail.setToAddresses(toAddresses); | |
mail.setSubject(instanceURL +':'+LibraryName+'-Files download URLs'); | |
mail.setPlainTextBody(LibraryName+'-Files download URLs. Please refer the attachment.'); | |
mail.setHtmlBody(LibraryName+'-Files download URLs. Please refer the attachment.'); | |
mail.setFileAttachments(new Messaging.EmailFileAttachment[]{csvAttc}); | |
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment