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 an Existing File
Make a call to post a comment with an already uploaded file.
To post a comment and attach an existing file (already uploaded to
Salesforce) to the comment, create a ConnectApi.CommentInput object to pass to postCommentToFeedElement(communityId, feedElementId,
comment,
feedElementFileUpload).
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 = 'I attached this file from Salesforce Files.';
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.contentDocumentId = '069D00000001rNJ';
19
20commentInput.capabilities = commentCapabilitiesInput;
21
22ConnectApi.Comment commentRep = ConnectApi.ChatterFeeds.postCommentToFeedElement(Network.getNetworkId(), feedElementId, commentInput, null);