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
Anvesh SinghAnvesh Singh 

ContentDocumentLink Limitations when querying using LinkEntityId as filter

Hi All, my apologies if this has been asked somewhere else. I didn't find any answer hence I have to post this question.

USE CASE: 
I am using database.query(queryString);
In queryString = 'SELECT id,linkEntityId,ContentDocumentId FROM ContentDocumentLink WHERE linkEntityID IN :listofRecords';

Here "listOfRecords" is a set of Ids (approx 5000 ids).
The above query returns only 6 contentDocumentLink.
But my org has more than 6 contentDocumentLink for those "listOfRecords".

How do I know if there are more than 6 files?
Because when I run the same query with selected linkEntityIds or hardcoded linkEntityIds (10 "listOfRecords") I get more than 6 records.

Question
So anyone has any idea is there any limitation on LinkEntityId when used as a filter in ContentDocumentLink?
David Zhu 🔥David Zhu 🔥
There is a "Query All Files" setting to be enabled in App Permissions section in Profile or permission set setting. It is unchecked by default.
Anvesh SinghAnvesh Singh
@DavidZhu
Thanks for the quick reply. But this also didn't solve the problem.
What I did:
  1. I created a permission set (with "Query All Files") and assigned to the user from which I was running the query.
  2. And then ran the query. But still, didn't get all the files.
Workaround:
  1. ​​​​​​​I divided the number of records into different sets. for ex: If "listOfRecords" is a having (approx 5000 ids)..Then created a 5 set of Ids.
  2. Then I created 5 different query strings with above 5 set of ids. And five different Database.query(queryString1), Databse.query(queryString2)..up to 5.
  3. And merged all the results in one list. And got all the files.

But this is not a nice workaround. 

So I am still open to any more suggestions.