Query Chatter Feed, Topics, and Groups
Trusty old ChildRelationship
to the rescue:
for (ChildRelationship relation : SObjectType.Topic.getChildRelationships())
system.debug(relation);
Relevant relationships and properties:
[getChildSObject=FeedComment;getField=ParentId;getRelationshipName=null;]
[getChildSObject=FeedItem;getField=ParentId;getRelationshipName=null;]
You should just be able to do:
SELECT Body, BestCommentId, CommentCount, LikeCount, Type,
(SELECT CommentBody FROM FeedComments)
FROM FeedItem WHERE ParentId = '<topic_id_here>'
If you want to filter on multiple Topic
parents, you could change your WHERE
clause to:
ParentId IN ('<topic1_id>', '<topic2_id>', 'etc.')
You can also do a Left Inner Join
to see which records have a relevant TopicAssignment
:
SELECT ... FROM FeedItem WHERE Id IN (
SELECT EntityId FROM TopicAssignment
WHERE EntityType = 'FeedItem'
AND TopicId IN ('<id1>', 'etc.')
)