function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AnidevAnidev 

Topics - Chatter Post

Hi All,

This is with respect to "Topics" in "Chatter Feed".
I can insert a feed with # tag and that particular feed becomes a "Topic"
However, I am unable to query "Chatter Feed" for a particular "Topic".
Can some one please suggest a probable solution.
Please pardon if this is a basic query.

Many thanks in advance.

Regards,
Anidev 
Best Answer chosen by Anidev
Nilesh Jagtap (NJ)Nilesh Jagtap (NJ)
Hi Anidev,

You can query the topicAssignment object to get the related feed Items as :

Map<Id, TopicAssignment> mapTA = new map<Id, TopicAssignment>([SELECT EntityId FROM TopicAssignment WHERE TopicId IN(Select ID From Topic where Name =:'TopicName')]);

//Prepare list of EntityIds as lstEntityIds.
list<String> lstEntityIds = new list<String>();

for(TopicAssignment oTA: mapTA.values()){
     lstEntityIds.add(oTA.EntityId)
}

//Now use this list of entity Ids from above query to get the FeedItem details.

list<FeedItem> lstFeeds = new list<FeedItem>([select ID, body FROM FeedItem WHERE Id IN : lstEntityIds]);




If this anwers you question mark this as best answer.

Thanks,
N.J

All Answers

Nilesh Jagtap (NJ)Nilesh Jagtap (NJ)
Hi Anidev,

You can query the topicAssignment object to get the related feed Items as :

Map<Id, TopicAssignment> mapTA = new map<Id, TopicAssignment>([SELECT EntityId FROM TopicAssignment WHERE TopicId IN(Select ID From Topic where Name =:'TopicName')]);

//Prepare list of EntityIds as lstEntityIds.
list<String> lstEntityIds = new list<String>();

for(TopicAssignment oTA: mapTA.values()){
     lstEntityIds.add(oTA.EntityId)
}

//Now use this list of entity Ids from above query to get the FeedItem details.

list<FeedItem> lstFeeds = new list<FeedItem>([select ID, body FROM FeedItem WHERE Id IN : lstEntityIds]);




If this anwers you question mark this as best answer.

Thanks,
N.J
This was selected as the best answer
AnidevAnidev
Hi N.J

Worked like a charm.

Thanks once again.
Anidev