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.
Share a Feed Element (in Version 39.0 and Later)
Call a method to share a feed element.
Call postFeedElement(communityId,
feedElement) to share a feed
element.
1// Define the FeedItemInput object to pass to postFeedElement
2ConnectApi.FeedItemInput feedItemInput = new ConnectApi.FeedItemInput();
3feedItemInput.subjectId = 'me';
4ConnectApi.TextSegmentInput textSegmentInput = new ConnectApi.TextSegmentInput();
5textSegmentInput.text = 'Look at this post I'm sharing.';
6// The MessageBodyInput object holds the text in the post
7ConnectApi.MessageBodyInput messageBodyInput = new ConnectApi.MessageBodyInput();
8messageBodyInput.messageSegments = new List<ConnectApi.MessageSegmentInput>();
9messageBodyInput.messageSegments.add(textSegmentInput);
10feedItemInput.body = messageBodyInput;
11
12ConnectApi.FeedEntityShareCapabilityInput shareInput = new ConnectApi.FeedEntityShareCapabilityInput();
13shareInput.feedEntityId = '0D5R0000000SEbc';
14ConnectApi.FeedElementCapabilitiesInput feedElementCapabilitiesInput = new
15ConnectApi.FeedElementCapabilitiesInput();
16feedElementCapabilitiesInput.feedEntityShare = shareInput;
17feedItemInput.capabilities = feedElementCapabilitiesInput;
18// Post the feed item.
19ConnectApi.FeedElement feedElement =
20ConnectApi.ChatterFeeds.postFeedElement(Network.getNetworkId(), feedItemInput);