3

I'm trying to query all the ContentDocumentLinks related to a list of about 25000 accounts. This yields no results. However, if I limit the initial account query to only 800 accounts I do find a ContentDocumentLink. Is there some limitation for ContentDocumentLinks that I'm not aware of?

Account[] accs = [SELECT Id 
                  FROM Account 
                  WHERE Aantal_opportunities_ongefilterd__c = 0 
                  AND Type != 'Agent'
                  AND Temp_account_niet_verwijderen__c = false
                  AND Aantal_registraties_ongefilterd__c = 0 
                  AND Aantal_bewakingen_ongefilterd__c = 0
                  AND CALENDAR_YEAR(CreatedDate) = 2014
                  AND Id NOT IN (SELECT Account__c FROM Factuur__c)
                  AND Id NOT IN (SELECT RelatedToId FROM EmailMessage)];
Set<Id> accIds = new Set<Id>();
for(Account acc : accs){
    accIds.add(acc.Id);
}
System.debug('Number of contentdocumentlinks: ' + [SELECT COUNT(Id) FROM ContentDocumentLink WHERE LinkedEntityId IN :accIds]);

USER_DEBUG|[15]|DEBUG|Number of contentdocumentlinks: (AggregateResult:{expr0=0})

Account[] accs = [SELECT Id 
                  FROM Account 
                  WHERE Aantal_opportunities_ongefilterd__c = 0 
                  AND Type != 'Agent'
                  AND Temp_account_niet_verwijderen__c = false
                  AND Aantal_registraties_ongefilterd__c = 0 
                  AND Aantal_bewakingen_ongefilterd__c = 0
                  AND CALENDAR_YEAR(CreatedDate) = 2014
                  AND Id NOT IN (SELECT Account__c FROM Factuur__c)
                  AND Id NOT IN (SELECT RelatedToId FROM EmailMessage)
                  LIMIT 800];
Set<Id> accIds = new Set<Id>();
for(Account acc : accs){
    accIds.add(acc.Id);
}
System.debug('Number of contentdocumentlinks: ' + [SELECT COUNT(Id) FROM ContentDocumentLink WHERE LinkedEntityId IN :accIds]);

USER_DEBUG|[16]|DEBUG|Number of contentdocumentlinks: (AggregateResult:{expr0=1})

1 Answer 1

1

You can see my same question here, but I had to create a Salesforce support case to resolve it. They enable some permission on their end to allow queries with greater than 2,000 records in the LinkedEntityId filter to return accurate results. This is covered in the following known issue.

1
  • Thank you! That's a very informative question and answer that you've got there
    – Kasper
    Mar 6, 2021 at 2:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .