For FeedItems this works in SOQL:

[SELECT Id FROM FeedItem WHERE Parent.Type = :mySObjectType]

But for FeedComment it is not a valid query:

Didn't understand relationship 'Parent' in field path

So I also tried to filter by key prefix:

String prefix = mySObjectType.getDescribe().getKeyPrefix() + '%';
[SELECT Id FROM FeedComment WHERE ParentId LIKE :prefix]

leads to:

invalid operator on id field

Is there any other workaround, or even a clean way to select Comments posted on a parent of a certain type?

EDIT: Also tried

[SELECT Id FROM FeedComment WHERE FeedItem.Parent.Type = :mySObjectType]

Didn't understand relationship 'FeedItem' in field path

2 Answers 2


Sometimes fields declared as Reference do not really work as references. In such cases you need to use some ugly workarounds like this one:

SELECT Id, FeedItemId, ParentId, RelatedRecordId FROM FeedComment WHERE FeedItemId IN ( Select id from FeedItem WHERE Parent.Type = :mySObjectType )
  • Hmmm.. wasn't sure about this, cause it "querys" or lets say doublechecks way more Items than I need. But it is a workaround of cause! Let's wait for about 24 hours and if nothing else pops up I'll accept this as an answer!
    – itsmebasti
    Commented Mar 9, 2017 at 10:42

In addition to the answer already presented, you can't use LIKE operator on an id field, as mentioned in the docs

The LIKE operator is supported for string fields only.

Id is not a string field, hence you can't use LIKE with Id fields.

As for the FeedComment object, I think the referential ids not being accessible via SOQL, is because this object is not supported to be used directly, as mentioned in the documentation

The FeedComment is not directly accessible and must be accessed via an Entity Feed

Sample SOQL to access FeedComment

SELECT Id, (SELECT Id, CommentBody, CreatedDate, CreatedById, 
                   CreatedBy.FirstName, CreatedBy.LastName
             FROM FeedComments )  
FROM [sObject]Feed 
  • 1
    Thanks for your response! I prefer the 'WHERE FeedItemId IN' approach for my case, since I only need Comments for a certain period, so I won't need to query all the FeedItems. The Documentation link is really helpful!
    – itsmebasti
    Commented Mar 10, 2017 at 13:00

You must log in to answer this question.

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