I am creating my file using the following code:

ContentVersion cv = new ContentVersion();
cv.VersionData = pdfContent;
cv.Title = fileName;
cv.PathOnClient = filename;
cv.Description = 'to-be-processed'
insert cv;

insertedCv = [SELECT Id, ContentDocumentId FROM ContentVersion WHERE Id = :cv.Id LIMIT 1];

if (recordId != null && recordId != '') {
    ContentDocumentLink contentlink = new ContentDocumentLink();
    contentlink.LinkedEntityId = recordId;
    contentlink.ContentDocumentId = insertedCv.ContentDocumentId;
    contentlink.ShareType = 'I';
    contentlink.Visibility = 'AllUsers';
    insert contentlink;

The recordId variable contains the Account Id of the external user.

This code gets executed when an external user uploads file through a custom LWC file upload.

The files gets created successfully, but I want there's a scheduled batch that will process the files that was uploaded. The problem is that the admin user can't query the content versions.

The query for getting the content versions:

SELECT Id FROM ContentVersion WHERE Description = 'to-be-processed'

I also tried to execute the query on the developer console, but it returns empty array.

It's weird because when I try querying it with specific content document id, it retrieves the record. Query:

SELECT Id, ContentDocumentId FROM ContentVersion WHERE ContentDocumentId = 'specificid'
  • 1
    The answer here explains this behaviour. Essentially SOQL won't always return the files a user has access to unless you've specified an ID. Nov 29, 2023 at 3:22
  • 1
    Right, I've missed that one. But I found a solution for it. I'll update my question. Thank you.
    – Carl Ortiz
    Nov 29, 2023 at 3:36
  • That's great. If that has solved it, you should answer your own question so that others in the community can easily find it if they have similar issues in the future. Nov 29, 2023 at 4:42

1 Answer 1


Based on this docs, which was also mentioned on this question, it says:

Note: Depending on how files are shared, queries on ContentDocument and ContentVersion without specifying an ID won't return all files a user has access to. For example, if a user only has access to a file because they have access to a record that the file is shared with, the file won't be returned in a query such as "SELECT Id FROM ContentDocument."

But you can still allow a user to query the documents without specifying an ID. Just create a permission set and enable "Query All Files" or just follow this steps mentioned in this link.

You must log in to answer this question.

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