Given a ContentDocument, I need a way to use SOQL to find any FeedItems that the ContentDocument may be related to.

I hoped that ContentDocumentLink would work, but that just seems to give me the case and the user, but not the actual post in the feed.

I tried to do a simple query on FeedItem to see if I can just get it from RelatedRecordId

Select Id FROM FeedItem Where RelatedRecordId = '123AAA'

but then I get the error field "'RelatedRecordId' can not be filtered in a query call"

I cannot think of any other way to get to the FeedItems.

1 Answer 1


Consider querying FeedAttachment, which represents an attachment to a FeedItem.

Knowing that you already have the ContentDocumentId, you can build the query as follows :

SELECT Id, RecordId, FeedEntityId 
from FeedAttachment 
where RecordId IN ( select Id from ContentVersion where ContentDocumentId ='069XXXXXXXXXXXXXXX')

FeedEntityId is the FeedItem Id and RecordId is the ContentVersion Id

Note: Seems that there is some limitation in accessing FeedEntity.FieldName in same query so you can build a set of FeedEntityIds and run another SOQL to retrieve more details on FeedItem if needed.

Refer to FeedAttachment documentation for more details

  • Thanks, too bad about not being able to get the FeedEntitiy fields, but I think this will work for what I need.
    – Scott B
    Mar 4, 2021 at 16:04

You must log in to answer this question.

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