We have a set of ContentVersion records that have been inserted by users via a FeedItem post. Unfortunately because Chatter groups has many functional limitations we have to migrate these files to regular ContentWorkspace.

However, because the files were inserted via an individual FeedItem, when we attempted to select them programmatically to get their ContentDocumentId for a new ContentDocumentLink they are not being returned even for System Administrator:


System.debug(LoggingLevel.Warn,'FeedItems: '+[SELECT COUNT() FROM FeedItem WHERE Type='ContentPost' AND CreatedDate >= :startDate AND CreatedDate <= :endDate AND IsDeleted=false]);

Returns 2000+ records...

Set<Id> cdIds = new Set<Id>();
List<ContentDocumentLink> cdls = new List<ContentDocumentLink>();

    for(ContentVersion cv : [SELECT ContentDocumentId FROM ContentVersion 
                              WHERE IsLatest=true AND Id IN 
                                 (SELECT RelatedRecordId FROM FeedItem WHERE Type='ContentPost' AND CreatedDate >= :startDate AND CreatedDate <= :endDate AND IsDeleted=false)]){
    // no records returned

Returns no records...

If I manually share the record to a library (via the UI), and than select the FeedItem directly, I can now see the ContentDocumentId?

1 Answer 1


I just tried to replicate your behaviour it worked fine for me.

  1. Created two sample chatter posts and queried them. As they didn't have any related files, so their relatedRecordId field was empty.
  2. Created a chatter post with a file and it properly returned the relatedRecordId.
  3. If instead of uploading the file in a chatter post, you directly upload to files section in chatter, they are not returned by this query.


  1. Can you verify that "Content User" feature license is assigned to user who is executing the queries?
  2. Verify that the query returning 2k records, has a Not Null relative Record id in results?
  • 1. Did you create the content post posts as your user, or another user (these are community users). They can create contentversions - so I doubt its a problem with their license. The chatter posts are created programmatically via APEX. And SOQL does not allow you to filter on relatedrecordid = null Jan 14, 2016 at 3:30

You must log in to answer this question.

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