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 New File (Binary) Attachment
Call a method to post a feed element with a new file.
This example calls postFeedElement(communityId, feedElement,
feedElementFileUpload) to post a feed item
with a new file (binary)
attachment.
1ConnectApi.FeedItemInput input = new ConnectApi.FeedItemInput();
2input.subjectId = 'me';
3
4ConnectApi.ContentCapabilityInput contentInput = new ConnectApi.ContentCapabilityInput();
5contentInput.title = 'Title';
6
7ConnectApi.FeedElementCapabilitiesInput capabilities = new ConnectApi.FeedElementCapabilitiesInput();
8capabilities.content = contentInput;
9
10input.capabilities = capabilities;
11
12String text = 'These are the contents of the new file.';
13Blob myBlob = Blob.valueOf(text);
14ConnectApi.BinaryInput binInput = new ConnectApi.BinaryInput(myBlob, 'text/plain', 'fileName');
15
16ConnectApi.ChatterFeeds.postFeedElement(Network.getNetworkId(), input, binInput);