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!

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);
    }
}
| improve this answer | |
  • Is there a way to access it in a trigger? – user3684 Aug 29 '13 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 '13 at 5:34
  • Hi. I got it to work off the FeedItem object. Thank you so much for you help! – user3684 Aug 30 '13 at 2:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.