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
sun tarsun tar 

How to retrieve @mentioned user id from FeedItem ?

Hi all,

Can any one guide me how to retrieve @mentioned user id from the feedItem in chatter.?

Thanks in advance.
Hi , 

You can use the new Chatter API in Apex to do this. It's in developer preview currently and is on by default in all Developer Edition orgs. 

Here's an example of how to use it:

String communityId = null;
String feedItemId = 'YOUR_FEEDITEM_ID';

ConnectApi.FeedItem feedItem = ConnectApi.ChatterFeeds.getFeedItem(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: ' +;
        System.debug('Mentioned user id: ' +;