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
Pooja Bisht 20Pooja Bisht 20 

ContentDocumentLink returning only one record where LinkedEntity.Type = User

I am creating an enhanced note under Contact and adding the same note to another custom object called Custom Note while creating the note itself.

I have written After Insert trigger on ContentVersion where ContentDocument.FileType == 'SNOTE'. The issue here is that on quering ContentDocumentLink in trigger, the query is returning only one record where LinkedEntity.Type is User whereas using the same query in developer console, its returning 3 records, 1 for Contact, 1 for User and 1 for Custom object (Custom Note)


here is the code:

public void createTasksforEnhancedNotes(List<ContentVersion> notes){
    
    Set<Id> noteIdSet = new Set<Id>();
    for(ContentVersion each : notes){
        noteIdSet.add(each.ContentDocument.Id);
    }
    
    if(noteIdSet != null && !noteIdSet.isEmpty()){
        List<ContentDocumentLink> contentLinkList = [SELECT ContentDocument.Title, ContentDocumentId, LinkedEntityId FROM ContentDocumentLink 
                                                     WHERE ContentDocumentId IN :noteIdSet];
        
    }            
            
}


Please help and explain why the query is returning different result in trigger and developer console
AnudeepAnudeep (Salesforce Developers) 
Hi Pooja, 

Can you try filtering your query as shown in the example and confirm if it returns the same results in your trigger and developer console? 
SELECT ContentDocument.title FROM ContentDocumentLink WHERE ContentDocumentId = '069D00000000so2' AND LinkedEntityId = '0D5000000089123'

Anudeep
raviteja p 38raviteja p 38
Hi Pooja,
I'm also facing the same issue,did you find the fix/ root cause for it? If yes can you please let me know what it is?