34

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.

  • "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 '12 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 '12 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. – CoryCowgill Jul 25 '16 at 20:13
  • @CoryCowgill What if you just add the user to all libraries? Then they have access. – Adrian Larson Jul 27 '16 at 14:21
16

Just found out today that with the Spring 19' update there is a new setting in the "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!

6

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
  • 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 '17 at 18:00
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.

6

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.

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

3

A bit late but this worked for me

SELECT ContentDocumentId,ContentDocument.Title, ContentDocument.CreatedDate,LinkedEntityId
FROM ContentDocumentLink where LinkedEntityId in ( SELECT Id FROM User)
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.