function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
davidleckenbydavidleckenby 

Not getting a value from SOQL query as expected when using a bind variable

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

    }
}
Hi Guys - 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]; 
        
        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);               
  }

Thank you!
Jithesh VasudevanJithesh Vasudevan
What is the error you are getting if there is any?