I'm trying to retrieve some ContentVersion records, but I'm having a lot of issues with it. After some research it seems as if the records are divided into two 'sets' as it were, and Salesforce in most cases refuses to return records from one of the sets. What's going on?! This might sound vague, but please read on.

Example 1

For example, when I query for two records, one from 'set A' and one from 'set B' like this:

SELECT Id FROM ContentVersion WHERE Id IN ('068C0000002LRddIAG','068C000000180RyIAI')

I get the 2 records, as expected. However, when I try

SELECT Id FROM ContentVersion WHERE Id = '068C0000002LRddIAG' OR Id = '068C000000180RyIAI'

I get only 1 record, which is completely odd! If I query them individually by Id, I do get them returned, so they certainly exist. Does somebody have a clue what's going on?

Example 2

More oddness. I only get the ContentVersions from set B returned when I query by Id, but not otherwise. If I do this:

SELECT Id FROM ContentVersion WHERE Title = 'UniqueTitle'

I get 0 results. However, when I make the query more strict by adding an Id clause:

SELECT Id FROM ContentVersion WHERE Title = 'UniqueTitle' AND Id = '068C0000002LRddIAG'

I do get the 1 record as result. In other words: if I don't literally query by Id, I don't get any results whatsoever from the second set of records.


A pointer might be that the two sets are like this, as far as I can see:

  • set A: ContentVersion records that are uploaded through the UI
  • set B: ContentVersion records that were created when I uploaded FeedItem records through the API (type = 'ContentPost' with ContentData filled with a Base64 encoded blob)

Somehow, the latter did create a structure of FeedItem, FeedAttachment, ContentDocument and ContentVersion, but they almost never get returned in SOQL searches, except if I mention the Id of the ContentVersion explicitly, and even then not in all cases (e.g. above example where I mix records from set A and set B).


  • 3
    Does the behavior change with parentheses around the second query's where clause conditions? WHERE (Id = '068C0000002LRddIAG' OR Id = '068C000000180RyIAI')
    – Mark Pond
    Commented Mar 16, 2016 at 17:14
  • 2
    Have you tried querying each individually? I.e. Where x = a; where x = b. My be helpful to troubleshoot if you can see what they each return.
    – zainogj
    Commented Mar 16, 2016 at 17:16
  • 1
    Looks very odd. Can you add several more filed to the select clause and compare them? Especially PublishStatus, ContentDocumentId. Because there are several restrictions in the API when the results are not returned If you query versions in the API, versions with a PublishStatus of Upload Interrupted are not returned developer.salesforce.com/docs/atlas.en-us.api.meta/api/…
    – steals
    Commented Mar 16, 2016 at 18:19
  • @MarkPond the parentheses make no difference. I'm really clueless. I have added another example which might shed some light on the issue... Commented Mar 16, 2016 at 20:18
  • @zainogj yes I did that. The records are both fine, functionally. I can also navigate to the records in the UI and properly see and/or download the document if I want.... Commented Mar 16, 2016 at 20:21

1 Answer 1


In this original example, could you please explain how each version is shared:

SELECT Id FROM ContentVersion WHERE Id = '068C0000002LRddIAG' OR Id = '068C000000180RyIAI'

Which of the 2 versions are returned in the query?

I gather at least 1 of these 2 versions is shared with a record. You mention it also shows it shared with the owner, however, all files will have a ContentDocumentLink to the owner unless the file is managed by a Content Library. This statement would apply to a file which only had ContentDocumentLinks to records and to the owner:

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

If you can specify the ContentDocumentLinks for each file, that would be helpful. Also, is the user running the query an admin (do they have the modify all data permission), or is it a standard user?

If either of the files are shared with the a Chatter group, please specify if the group is a public or private group, and if the user executing the query is a member of the group.

I know I'm requesting a lot of information, but I'll try to help get to the bottom of this.

As you've noticed by now, there are a lot of rules for queries on ContentVersion which different from standard records, and this is due to how access can be gained through many means.

  • You should probably reorganize your answer. I read your opening asking for more detail and assumed you just had questions for the OP.
    – Adrian Larson
    Commented Mar 17, 2016 at 16:58

You must log in to answer this question.

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