Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
Post a Feed Element with a Mention
Call a method or use the ConnectApiHelper repository to post a feed.
You can post feed elements with mentions two ways. Use the ConnectApiHelper repository
on GitHub to write a single line of code, or use this
example, which calls postFeedElement(communityId,
feedElement).
1ConnectApi.FeedItemInput feedItemInput = new ConnectApi.FeedItemInput();
2ConnectApi.MentionSegmentInput mentionSegmentInput = new ConnectApi.MentionSegmentInput();
3ConnectApi.MessageBodyInput messageBodyInput = new ConnectApi.MessageBodyInput();
4ConnectApi.TextSegmentInput textSegmentInput = new ConnectApi.TextSegmentInput();
5
6messageBodyInput.messageSegments = new List<ConnectApi.MessageSegmentInput>();
7
8mentionSegmentInput.id = '005RR000000Dme9';
9messageBodyInput.messageSegments.add(mentionSegmentInput);
10
11textSegmentInput.text = 'Could you take a look?';
12messageBodyInput.messageSegments.add(textSegmentInput);
13
14feedItemInput.body = messageBodyInput;
15feedItemInput.feedElementType = ConnectApi.FeedElementType.FeedItem;
16feedItemInput.subjectId = '0F9RR0000004CPw';
17
18ConnectApi.FeedElement feedElement = ConnectApi.ChatterFeeds.postFeedElement(Network.getNetworkId(), feedItemInput);