2

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

5

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 )
1
  • 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!
    – Basti
    Mar 9 '17 at 10:42
1

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
  • 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!
    – Basti
    Mar 10 '17 at 13:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.