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 Comment with a New File
Call a method to post a comment with a new file.
To post a comment and upload and attach a new file to the comment, create a ConnectApi.CommentInput object and a ConnectApi.BinaryInput object to pass to the postCommentToFeedElement(communityId, feedElementId, comment,
feedElementFileUpload)
method.
1String feedElementId = '0D5D0000000KtW3';
2
3ConnectApi.CommentInput commentInput = new ConnectApi.CommentInput();
4
5ConnectApi.MessageBodyInput messageBodyInput = new ConnectApi.MessageBodyInput();
6ConnectApi.TextSegmentInput textSegmentInput = new ConnectApi.TextSegmentInput();
7
8textSegmentInput.text = 'Enjoy this new file.';
9
10messageBodyInput.messageSegments = new List<ConnectApi.MessageSegmentInput>();
11messageBodyInput.messageSegments.add(textSegmentInput);
12commentInput.body = messageBodyInput;
13
14ConnectApi.CommentCapabilitiesInput commentCapabilitiesInput = new ConnectApi.CommentCapabilitiesInput();
15ConnectApi.ContentCapabilityInput contentCapabilityInput = new ConnectApi.ContentCapabilityInput();
16
17commentCapabilitiesInput.content = contentCapabilityInput;
18contentCapabilityInput.title = 'Title';
19
20commentInput.capabilities = commentCapabilitiesInput;
21
22String text = 'These are the contents of the new file.';
23Blob myBlob = Blob.valueOf(text);
24ConnectApi.BinaryInput binInput = new ConnectApi.BinaryInput(myBlob, 'text/plain', 'fileName');
25
26ConnectApi.Comment commentRep = ConnectApi.ChatterFeeds.postCommentToFeedElement(Network.getNetworkId(), feedElementId, commentInput, binInput);