Skip to main content

I installed a Staff Recruiting app that came with an object called Candidate. Resumes and cover letters get uploaded as related files. I want to add columns in a Candidate report for resume and cover letter links. It seems easy enough but it turns out it's not possible. The solution I came up with was to create an automation through Flow or Process Builder to populate a custom field on the Candidate object with the file url when a record is uploaded, but that didn't seem possible either. It seems the only possibility is to do this with an apex trigger, but I don't know how to code. Does anyone know how I might be able to do this without coding or could help me generate the code for the trigger? Much thanks

6 Antworten
  1. 6. Mai 2023, 07:23

    Jason,

     

    If you want to trigger your automation when a file is uploaded, you won't be able to do it using Flows.

    Files are represented as ContentDocument, ContentVersion, ContentDocumentLink and none of these objects are available as the triggering object for record triggered flow.

    You will have to use Apex Trigger for this.

    Try this sample code.

     

    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 );

    }

    system.debug('--parentIds--'+ parentIds);

    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.Resume_Link__c = '/lightning/r/ContentDocument/'+ cdl.ContentDocumentId + '/view';

    }

    else if(cdl.ContentDocument.Title.contains('Cover')){

    candidate.Cover_Letter_Link__c = '/lightning/r/ContentDocument/'+ cdl.ContentDocumentId + '/view';

    }

    }

    system.debug('--parentIds--'+ candidate);

    updateCandidateList.add(candidate);

    }

    update updateCandidateList;

    }

0/9000