54

According to the Salesforce documentation on ContentDocument

Users (including users with the “View All Data” permission) can only query files they have access

I find this very strange. Why would a System Administrator not be allowed to see all ContentDocument records within Salesforce?

Is there a way to circumvent this limitation?

EDIT: The weirdest thing about all this is that the Admin user can see the ContentDocument in the Salesforce web interface.. but they can't be obtained through the API. That makes little sense. I'd expect the API to show as much or more data than the web interface, not the opposite.

4
  • "Why would a System Administrator not be allowed to see all ContentDocument records within Salesforce?" : Are you able to change the settings for System Admins and make it disable for them?
    – Forceguru
    Oct 12, 2012 at 3:22
  • What do you mean? My main objective is not to hide the ContentDocuments that do not belong to the administrator. I want to see all the ContentDocument records through the Salesforce API. Since the administrator can see them within the web interface, I'd expect him to be able to see them through the API.
    – GuiSim
    Oct 16, 2012 at 17:50
  • 2
    This question was asked several years ago and the USING SCOPE does not solve ALL permutations. The question is how do you SOQL to get all ContentDocument records without doing work arounds like querying all the ContentDocumentLink records. Jul 25, 2016 at 20:13
  • @CoryCowgill What if you just add the user to all libraries? Then they have access.
    – Adrian Larson
    Jul 27, 2016 at 14:21

7 Answers 7

52

Just found out today that with the Spring 19' update there is a new setting in the "Setup -> Permission Sets -> (choose an existing or create a new one) -> App Permission -> Content -> Query All Files: Allows View All Data users to SOQL query all files in the org".

This is not enabled by default for the admin user but you can at least enable it in a Profile/Permissions Set.

Also, now documented in the API Documentation.

Have fun!

2
  • 3
    Full path: Setup->Permission Sets -> (choose an existing or create a new one) ->App Permission -> Under the 'Content' section you will see 'Query All Files'.
    – Json
    Mar 12, 2020 at 11:29
  • 3
    Does anyone know if this works from the Developer Console? I'm still only seeing my ContentDocuments, and I am System Admin w/ the permission set. Jan 7, 2022 at 19:06
8

As advised by David Ha, you should add a "USING SCOPE" option in your SOQL query in order to retrieve all the ContentDocument records. Strangely, I found that "USING SCOPE Everything" restricts the data to Owned files only, while "USING SCOPE Team" gives all ContentDocument regardless of Owner and sharing.

So this query did the trick for me (on API version > 32) :

Select Id, Title, FileExtension, CreatedDate From ContentDocument USING SCOPE Team
1
  • 1
    USING SCOPE Team appears to rely on you running the query as a user "above" the users owning the ContentDocument in Salesforce's role hierarchy. It appears that any users lateral to you inside the same role or in a separate part of the tree will not have their files appear. It appears the only way to truly get every file is to query ContentDocumentLink with every object type that supports linking ContentDocument records.
    – Nick
    Dec 6, 2017 at 18:00
7

If you want to delete files that are related to a single object then export ContentDocumentIds from below query and then use those ContentDocumentIds to delete files which are related to object.

SELECT ContentDocumentId,ContentDocument.CreatedDate,LinkedEntityId FROM ContentDocumentLink where LinkedEntityId in ( SELECT Id FROM User)

You can replace User with your ObjectApi name.

6

Official response from SFDC Support is this is working as designed.

There is no ability to query all content programmatically via SOQL which I suspected. You have to query ContentDocumentLink with Filters and somehow build filter critieria across all objects in your org.

=======================CASE INFO=====================

However, this is how this functionality is designed.

As a suggestion, queries can only run under the previously mentioned conditions.

Also, the same is mentioned in the below document:

'To query a file that is shared only with a record, you must specify the content ID of the file.'

That is why ContentDocuments will be visible in the below scenarios only:

  • If the content document from a public group?
  • If the content document shared to the requesting user?
  • If the content document shared to a group that the requesting user is a member of?

Please let me know in case you have any further questions for me.

5

A bit late but this worked for me

SELECT ContentDocumentId,ContentDocument.Title, ContentDocument.CreatedDate,LinkedEntityId
FROM ContentDocumentLink where LinkedEntityId in ( SELECT Id FROM User)
4

We had a similar issue with Report and it turned out the reports were under the Private space of the owners. In our case, this query gives us the full data:

Select id,name,ownerid from report USING SCOPE allPrivate

0

The content data model is slightly different than other objects in salesforce.

The way it works is that each document is represented as a ContentDocument. Each ContentDocument contains one or more ContentVersion objects (depending on how many versions of a given document have been uploaded). When you are query some fields on ContentDocument, like description, you are just pulling the description from the latest ContentVersion object. To determine which ContentVersion is the latest for a given document you can look at the LatestPublishedVersionId field.

So may be thats the reason why salesforce didnt show from Web UI.

You must log in to answer this question.

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