Make call or use the ConnectApiHelper repository to post a comment with a
mention.
You can post comments with mentions two ways. Use the ConnectApiHelper repository on GitHub to write a single line
of code, or use this example, which calls postCommentToFeedElement(communityId, feedElementId, comment,
feedElementFileUpload).
String communityId = null; String feedElementId = '0D5D0000000KtW3'; ConnectApi.CommentInput commentInput = new ConnectApi.CommentInput(); ConnectApi.MentionSegmentInput mentionSegmentInput = new ConnectApi.MentionSegmentInput(); ConnectApi.MessageBodyInput messageBodyInput = new ConnectApi.MessageBodyInput(); ConnectApi.TextSegmentInput textSegmentInput = new ConnectApi.TextSegmentInput(); messageBodyInput.messageSegments = new List<ConnectApi.MessageSegmentInput>(); textSegmentInput.text = 'Does anyone in this group have an idea? '; messageBodyInput.messageSegments.add(textSegmentInput); mentionSegmentInput.id = '005D00000000oOT'; messageBodyInput.messageSegments.add(mentionSegmentInput); commentInput.body = messageBodyInput; ConnectApi.Comment commentRep = ConnectApi.ChatterFeeds.postCommentToFeedElement(communityId, feedElementId, commentInput, null);