3

I am trying to achieve feed item to record with multiple @ mentions when status of record goes to Complete.Here is the sample code which creates a feed item to record with single @ mention.

         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>();
         textSegmentInput.text = 'Customer has completed the application';
          messageBodyInput.messageSegments.add(textSegmentInput);

         mentionSegmentInput.id = a.PermID; //a.PermID is the User Id
         messageBodyInput.messageSegments.add(mentionSegmentInput);

         feedItemInput.body = messageBodyInput;
         feedItemInput.feedElementType = ConnectApi.FeedElementType.FeedItem;
         // Use a record ID for the subject ID.
          feedItemInput.subjectId = a.Id ; //a.Id is the record ID
           ConnectApi.FeedElement feedElement = ConnectApi.ChatterFeeds.postFeedElement(null, feedItemInput, null);
1

2 Answers 2

4

To add more mentions, simply create more ConnectApi.MentionSegmentInput objects and add them to the messageBodyInput.messageSegments list before you call ConnectApi.ChatterFeeds.postFeedElement(). I agree with cricketlang's ConnectApiHelper suggestion too!

2

Thanks @alouie. Here is my solution

    ConnectApi.FeedItemInput feedItemInput = new ConnectApi.FeedItemInput();
         ConnectApi.MentionSegmentInput mentionSegmentInput = new ConnectApi.MentionSegmentInput();
**ConnectApi.MentionSegmentInput mentionSegmentInput2 = new ConnectApi.MentionSegmentInput();**
         ConnectApi.MessageBodyInput messageBodyInput = new ConnectApi.MessageBodyInput();
         ConnectApi.TextSegmentInput textSegmentInput = new ConnectApi.TextSegmentInput();
         messageBodyInput.messageSegments = new List<ConnectApi.MessageSegmentInput>();
         textSegmentInput.text = 'Customer has completed the application';
          messageBodyInput.messageSegments.add(textSegmentInput);

         mentionSegmentInput.id = a.PermID; //a.PermID is the User Id
         messageBodyInput.messageSegments.add(mentionSegmentInput);

         **mentionSegmentInput2.id = a.AuID; //a.AuID is the User Id
         messageBodyInput.messageSegments.add(mentionSegmentInput2);**        

         feedItemInput.body = messageBodyInput;
         feedItemInput.feedElementType = ConnectApi.FeedElementType.FeedItem;
         // Use a record ID for the subject ID.
          feedItemInput.subjectId = a.Id ; //a.Id is the record ID
           ConnectApi.FeedElement feedElement = ConnectApi.ChatterFeeds.postFeedElement(null, feedItemInput, null);

You must log in to answer this question.

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