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.
String communityId = null; String feedElementId = '0D5R0000000SBEr'; String codeSnippet = '<html>\n\t<body>\n\t\tHello, world!\n\t</body>\n</html>'; ConnectApi.CommentInput input = new ConnectApi.CommentInput(); ConnectApi.MessageBodyInput messageInput = new ConnectApi.MessageBodyInput(); ConnectApi.TextSegmentInput textSegment; ConnectApi.MarkupBeginSegmentInput markupBeginSegment; ConnectApi.MarkupEndSegmentInput markupEndSegment; messageInput.messageSegments = new List<ConnectApi.MessageSegmentInput>(); markupBeginSegment = new ConnectApi.MarkupBeginSegmentInput(); markupBeginSegment.markupType = ConnectApi.MarkupType.Code; messageInput.messageSegments.add(markupBeginSegment); textSegment = new ConnectApi.TextSegmentInput(); textSegment.text = codeSnippet; messageInput.messageSegments.add(textSegment); markupEndSegment = new ConnectApi.MarkupEndSegmentInput(); markupEndSegment.markupType = ConnectApi.MarkupType.Code; messageInput.messageSegments.add(markupEndSegment); input.body = messageInput; ConnectApi.ChatterFeeds.postCommentToFeedElement(communityId, feedElementId, input, null);