4

I'm writing a trigger off the CollaborationGroupFeed object and I want to grab the @ mentions information from a post - is this possible?

I see that the post is saved in the body field and it doesn't seem as if there's a place to hold the user information from the @ mentions. However, I know that when you post to a feed with an @ mentions, you can click on that link and be directed to the User's profile. So, Chatter does know who the user is, but it doesn't look like it's stored in the table.

Does anyone have an idea on if and how this can be captured within a trigger?

Thanks in advance!

1 Answer 1

4

You can retrieve the @-mentions using Chatter in Apex. Given a FeedItem SObject called myFeedItem, you can do something like this with v28.0 of the API:

String communityId = null;
ConnectApi.FeedItem fi = ConnectApi.ChatterFeeds.getFeedItem(communityId, myFeedItem.id);
List<ConnectApi.MessageSegment> messageSegments = fi.body.messageSegments;
for (ConnectApi.MessageSegment segment : messageSegments) {
    if (segment instanceof ConnectApi.MentionSegment) {
        ConnectApi.MentionSegment mention = (ConnectApi.MentionSegment) segment;
        System.debug('Name: ' + mention.name + ', id: ' + mention.user.id);
    }
}
3
  • Is there a way to access it in a trigger?
    – user3684
    Aug 29, 2013 at 1:52
  • Yes, as long as you can get the ID of the feed item from within the trigger. Can you provide an example of what your trigger will look like? I don't think that the CollaborationGroupFeed SObject is triggerable.
    – alouie
    Aug 29, 2013 at 5:34
  • Hi. I got it to work off the FeedItem object. Thank you so much for you help!
    – user3684
    Aug 30, 2013 at 2:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .