Soql query to access Topics associated with FeedItems in salesforce Chatter

2.3k views Asked by At

I am trying to access FeedItems and topics(tags) associated to each FeedItem in a chatter Group. I am not able to figure out the relationship between FeedItems and Topics tagged with FeedItem.

I am able to get all the FeedItems in a chatter Group using the following soql Query: SELECT c.id, c.CreatedDate, c.InsertedBy.Name FROM CollaborationGroupFeed c WHERE c.Parent.Name = 'Chatter_Group_name'

Similarly I can get all the Topics using following soql Query:

Select Id, Name from Topic

But i need to get each FeedItem with Topics tagged with it (if any).

Following is the image to better understand it. enter image description here

I need to get the topics mentioned in the black rectangle.

Can anyone help me to get the Required output? Let me know if Other information is required regarding this.

1

There are 1 answers

0
ArtieBrosius On

You need to query the TopicAssignment object like this:

List<TopicAssignment> myFeedItemFeedAssignments = [
SELECT
    Id,
    NetworkId,
    TopicId,
    Topic.Name,
    EntityId,
    EntityKeyPrefix
FROM
    TopicAssignment
WHERE
    EntityId IN :feedItemId

Each TopicAssignment record has a Name property

P.S. You might get more responses by posting on salesforce.stackexchange.com