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
Richard Cave09035942158259942Richard Cave09035942158259942 

find out who @mention someone in chatter feed

I have a trigger on the feed Item, I want to be able to find out in that feed if someone has @mention someone.  I did think of searching through the body of the feed item to search for @[firstname lastname] but they have seemed to have removed the brackets from the feeditem body.

Are the @mentioned stored in any salesforce table?

Thanks.
Best Answer chosen by Richard Cave09035942158259942
ShashankShashank (Salesforce Developers) 
@mentions are not stored separately in another object or table. They will just be stored as "@firstname lastname" in the body field if the feeditem object.

In order to find out if a user is actually @mentioned, you may have to use the Chatter API, as mentioned here: http://salesforce.stackexchange.com/questions/10047/retrieve-userid-of-mention-user-from-chatter-post-in-apex

All Answers

ShashankShashank (Salesforce Developers) 
@mentions are not stored separately in another object or table. They will just be stored as "@firstname lastname" in the body field if the feeditem object.

In order to find out if a user is actually @mentioned, you may have to use the Chatter API, as mentioned here: http://salesforce.stackexchange.com/questions/10047/retrieve-userid-of-mention-user-from-chatter-post-in-apex
This was selected as the best answer
Richard Cave09035942158259942Richard Cave09035942158259942
Thanks Shashank, that exactly what I needed.  I had to change the code slightly to this as getFeedItem has gone after api 31 and MentionSegment user.id was only in api 29.

   String communityId = null;
String feedItemId = 'feed id';

ConnectApi.FeedElement feedItem = ConnectApi.ChatterFeeds.getFeedElement(communityId, feedItemId);
List<ConnectApi.MessageSegment> messageSegments = feedItem.body.messageSegments;
for (ConnectApi.MessageSegment messageSegment : messageSegments) {
    if (messageSegment instanceof ConnectApi.MentionSegment) {
        ConnectApi.MentionSegment mentionSegment = (ConnectApi.MentionSegment) messageSegment;
        System.debug('Mentioned user name: ' + mentionSegment.name);
        System.debug('Mentioned user id: ' + mentionSegment.record);
    }