How to get @mentioned user from Feed Item in Salesforce?

Sample Code:

String communityId = null;
String feedItemId = '0D529000001ABmQCAW';//Sample FeedItem 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: ' +;
        System.debug('Mentioned user id: ' + mentionSegment.record);


No comments:

Post a Comment

Sharing is Caring!!! Share this with your friends!!!

submit to reddit