Populate the custom field with the file link #inSalesforce

Populate the custom field with the file link


trigger ContentDocumentLinkTrigger on ContentDocumentLink(after insert) {
    Set<String> parentIds = new Set<String>();
List<Candidate__c> updateCandidateList = new List<Candidate__c>();
    for (ContentDocumentLink cdl : Trigger.new){
        parentIds.add(cdl.LinkedEntityId);
    }
    for (Candidate__c candidate : [SELECT Id, (SELECT Id,ContentDocumentId, ContentDocument.Title,LinkedEntityId FROM ContentDocumentLinks where ContentDocument.Title like '%Resume%' or ContentDocument.Title like '%Cover Letter%' LIMIT 2 ) FROM Candidate__c WHERE Id IN :parentIds] ) {
        for(ContentDocumentLink cdl : candidate.ContentDocumentLinks){
            if(cdl.ContentDocument.Title.contains('Resume')){
                candidate.ResumeFile__c = '/lightning/r/ContentDocument/'+ cdl.ContentDocumentId + '/view';
            }
            else if(cdl.ContentDocument.Title.contains('Cover')){
                candidate.CoverLetterFile__c = '/lightning/r/ContentDocument/'+ cdl.ContentDocumentId + '/view';
            }
        }
        updateCandidateList.add(candidate);
    }
        update updateCandidateList;  
    
}

Comments