Newer Version Available

This content describes an older version of this product. View Latest

Post a Feed Element with a New File (Binary) Attachment

In version 36.0 and later, you can’t post a feed element with a new file in the same call. Upload files to Salesforce first, and then specify existing files when posting a feed element.

Important

This example calls the postFeedElement(communityId, feedElement, feedElementFileUpload) method 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);