2

Is it possible to post to case feed via apex trigger and @ mention a user ? I looked at the connect api but that didn't seem to work and the below code works but can't get @ mentions working with it.

            FeedItem fi = new Feeditem(
                    ParentId = case.Id,
                    Body     = 'Body',
                    Type     = 'TextPost'
                 );

1 Answer 1

4

You have to use the MentionSegment in order for the @Mention to work. See this page for an example: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/connectapi_examples_post_feed_element_mention.htm

ConnectApi.FeedItemInput feedItemInput = new ConnectApi.FeedItemInput();
ConnectApi.MentionSegmentInput mentionSegmentInput = new ConnectApi.MentionSegmentInput();
ConnectApi.MessageBodyInput messageBodyInput = new ConnectApi.MessageBodyInput();
ConnectApi.TextSegmentInput textSegmentInput = new ConnectApi.TextSegmentInput();

messageBodyInput.messageSegments = new List<ConnectApi.MessageSegmentInput>();

mentionSegmentInput.id = '005RR000000Dme9';
messageBodyInput.messageSegments.add(mentionSegmentInput);

textSegmentInput.text = 'Could you take a look?';
messageBodyInput.messageSegments.add(textSegmentInput);

feedItemInput.body = messageBodyInput;
feedItemInput.feedElementType = ConnectApi.FeedElementType.FeedItem;
feedItemInput.subjectId = '0F9RR0000004CPw';

ConnectApi.FeedElement feedElement = ConnectApi.ChatterFeeds.postFeedElement(Network.getNetworkId(), feedItemInput, null);

The feedItemInput.subjectId is where you set the parent ID.

2
  • 1
    While this link may answer the question, links tend to break over time. Can you add the relevant content here to make your answer more robust?
    – Adrian Larson
    Commented Sep 22, 2016 at 20:49
  • In that example above , is the subject Id field where the caseid goes ?
    – HSG
    Commented Sep 23, 2016 at 11:30

You must log in to answer this question.

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