Skip to content

Instantly share code, notes, and snippets.

@swapnilshrikhande
Created May 28, 2020 03:52
Show Gist options
  • Save swapnilshrikhande/73eb055a3f46a69c90f770366dc990ed to your computer and use it in GitHub Desktop.
Save swapnilshrikhande/73eb055a3f46a69c90f770366dc990ed to your computer and use it in GitHub Desktop.
Cloning Related Files, Here relating files from related case record to lead
trigger AttachFile on Lead (after insert) {
List<ContentDocumentLink> cdeInsertList = new List<ContentDocumentLink>();
System.debug('line3');
Map<Id, Id> caseId2 = new Map<Id, Id>();
for(Lead ldItr : Trigger.New) {
caseId2.put(ldItr.Case__c, ldItr.Id);
}
System.debug('line8');
for(ContentDocumentLink cdl : [SELECT
ContentDocumentId,Id,
IsDeleted,LinkedEntityId,
ShareType,SystemModstamp,
Visibility
FROM
ContentDocumentLink
WHERE
LinkedEntityId IN :caseId2.keySet()]){
ContentDocumentLink newCDE = cdl.clone(false, true, false, false);
newCDE.LinkedEntityId = caseId2.get(cdl.LinkedEntityId);
cdeInsertList.add(newCDE);
System.debug(newCDE);
}
insert cdeInsertList;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment