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 Rich-Text Feed Comment with a Code Block

Call a method to post a comment with a code block.
This example calls postCommentToFeedElement(communityId, feedElementId, comment, feedElementFileUpload) to post a comment with a code block.
1String communityId = null;
2String feedElementId = '0D5R0000000SBEr';
3String codeSnippet = '<html>\n\t<body>\n\t\tHello, world!\n\t</body>\n</html>';
4
5ConnectApi.CommentInput input = new ConnectApi.CommentInput();
6ConnectApi.MessageBodyInput messageInput = new ConnectApi.MessageBodyInput();
7ConnectApi.TextSegmentInput textSegment;
8ConnectApi.MarkupBeginSegmentInput markupBeginSegment;
9ConnectApi.MarkupEndSegmentInput markupEndSegment;
10
11messageInput.messageSegments = new List<ConnectApi.MessageSegmentInput>();
12
13markupBeginSegment = new ConnectApi.MarkupBeginSegmentInput();
14markupBeginSegment.markupType = ConnectApi.MarkupType.Code;
15messageInput.messageSegments.add(markupBeginSegment);
16
17textSegment = new ConnectApi.TextSegmentInput();
18textSegment.text = codeSnippet;
19messageInput.messageSegments.add(textSegment);
20
21markupEndSegment = new ConnectApi.MarkupEndSegmentInput();
22markupEndSegment.markupType = ConnectApi.MarkupType.Code;
23messageInput.messageSegments.add(markupEndSegment);
24
25input.body = messageInput;
26
27ConnectApi.ChatterFeeds.postCommentToFeedElement(communityId, feedElementId, input, null);