Skip to content

Instantly share code, notes, and snippets.

@Sunil02kumar
Created August 3, 2023 10:19
Show Gist options
  • Save Sunil02kumar/b8358ef287d5637fda317a2b30aad242 to your computer and use it in GitHub Desktop.
Save Sunil02kumar/b8358ef287d5637fda317a2b30aad242 to your computer and use it in GitHub Desktop.
Script to generate URL for download all files related to any record
string parentRecordId='0012800001IrqlyAAB';
string orgbaseUrl=URL.getSalesforceBaseUrl().toExternalForm();
string downloadAllFileUrl=orgbaseUrl+'/sfc/servlet.shepherd/version/download';
List<string> contentVersionIdList = new List<string>();
for(ContentDocumentLink cdl:[SELECT ContentDocumentId,ContentDocument.title,ContentDocument.LatestPublishedVersionId FROM ContentDocumentLink where LinkedEntityId =:parentRecordId]){
contentVersionIdList.add(string.valueof(cdl.ContentDocument.LatestPublishedVersionId));
}
downloadAllFileUrl = downloadAllFileUrl +'/'+string.join(contentVersionIdList,'/');
system.debug('***downloadAllFileUrl:'+downloadAllFileUrl);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment