Find your content:

Search form

You are here

How to query all Chatter Files attached to a record?


We're trying to build a custom Visualforce related list that will show all the Chatter Files that are related to a record. All files should be displayed, regardless of if they are explicitly shared with the user viewing the record. By having access to the record, the users automatically see all Chatter Files attached to that record.

Having some trouble finding the right tables to get that data back in the right way. Anyone done this before?

Attribution to: Matthew Lamb

Possible Suggestion/Solution #1

I think that the best way would be querying all ContentDocument related to one record.

You have to query an object with a subquery on AttachedContentDocument:

SELECT id,  (SELECT ContentDocumentid FROM AttachedContentDocuments) FROM sObject

So you don't need to specify the linkedntityId.

Attribution to: MarcoDev

Possible Suggestion/Solution #2

I believe that the FeedItem object is what you are looking for. Chatter posts with a file attachment will be of type "ContentPost", so I would try this for gathering all files for a particular record id:

SELECT ContentFileName FROM FeedItem WHERE Type = 'ContentPost' AND ParentId = '[RECORD_ID]'

Attribution to: Scott VonSchilling

Possible Suggestion/Solution #3

FeedItem is a linking object. It points to a ContentDocument record which is the file attachment and also has a parent link to the data record that the chatter post is related to. So read feeditems that have a ParentId of the data record you want, then use the associated lookup to the ContentDocument to find the ContentDocument.

Reference the Web Services API Developer's Guide. Search on FeedItem.

Attribution to: Brant Hanna

Possible Suggestion/Solution #4

On second though, use the LinkedEntityId field on ContentDocumentLink:

SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId = '[RECORD ID]'

Attribution to: Scott VonSchilling
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content