0
public class ELOUpload_Class {

    public static void ELOUpload_Method1 (List<ContentDocument> lstContentDoc) {

       //Create a set of all the incoming IDs
        Set<Id> contDocId = new Set<Id> (); 

        for (ContentDocument contDoc : lstContentDoc ) {

           contDocId.add(contDoc.Id);

        }
        system.debug('contDocId = ' + contDocId );  

        List <ContentDocumentLink> contDoclink = [SELECT Id, ContentDocumentId FROM ContentDocumentLink WHERE ContentDocumentId = '0692O0000003CSTQA2']; 

        system.debug('contDoclink   = ' + contDoclink );      

    }
}

I am working with ContentFiles and am trying to get a list to populate with some values from the ContentDocumentLink object. The code above (with hardcoded value) works fine and returns the values. However when trying to do it referencing the set variable (contDocId) in the code below I get no values returned. The contDocId is being pulled correctly too (which is the hardcoded value).

public class ELOUpload_Class {

    public static void ELOUpload_Method1 (List<ContentDocument> lstContentDoc) {

       //Create a set of all the incoming IDs
        Set<Id> contDocId = new Set<Id> (); 

        for (ContentDocument contDoc : lstContentDoc ) {

           contDocId.add(contDoc.Id);

        }
        system.debug('contDocId = ' + contDocId );  

        List <ContentDocumentLink> contDoclink = [SELECT Id, ContentDocumentId FROM ContentDocumentLink WHERE ContentDocumentId IN :contDocId LIMIT 1]; 

        system.debug('contDoclink   = ' + contDoclink );      

    }
}

Also here is the trigger so you can see all the code involved.

trigger ELOUpload_Trigger on ContentDocument (after insert) {
     ELOUpload_Class.ELOUpload_Method1 (Trigger.new);               
}
2

ContentDocumentLink records don't exist yet in the after insert event of ContentDocument. As a child record, they cannot be added until the insert DML for ContentDocument completes.

Your trigger will most likely need to be written against ContentDocumentLink, rather than ContentDocument. The exact implementation pattern will depend on your overall objective.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.