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'

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';

textSegmentInput.text = 'Could you take a look?';

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.

  • 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 Sep 22 '16 at 20:49
  • In that example above , is the subject Id field where the caseid goes ? – HSG Sep 23 '16 at 11:30

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.