Can anyone tell me how to get the id of the feedItem files?
Like I want to know the id(ContentDocument.LatestPublishedVersionId) of the files that are attached to the feeditem and feedcomment.
Please someone give me the soql for above usecase.

Thanks in advance

2 Answers 2


I think this chain of queries can help you

String feedItemId = '...';
FeedItem feedItem = [
    SELECT RelatedRecordId
    FROM FeedItem
    WHERE Id = :feedItemId

String relatedRecordId = feedItem.RelatedRecordId;

ContentVersion version = [
    SELECT ContentDocument.LatestPublishedVersionId 
    FROM ContentVersion
    WHERE Id = :relatedRecordId

String result = version.ContentDocument.LatestPublishedVersionId;
  • there is no ContentDocument.LatestPublishedVersionId in Contentversion class Apr 6, 2015 at 17:35
  • try to use through ContentDocumentId (this field must be in ContentVersion) and another one query
    – misha_m
    Apr 6, 2015 at 17:44

I think below link may help you to understand the flow of the content Document and content Version relationship.still your question is not clear to me so i can't help you to give proper query but you can refer this link.


You must log in to answer this question.

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