Newer Version Available
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).
1String communityId = null;
2String feedElementId = '0D5D0000000KtW3';
3
4ConnectApi.CommentInput commentInput = new ConnectApi.CommentInput();
5ConnectApi.MentionSegmentInput mentionSegmentInput = new ConnectApi.MentionSegmentInput();
6ConnectApi.MessageBodyInput messageBodyInput = new ConnectApi.MessageBodyInput();
7ConnectApi.TextSegmentInput textSegmentInput = new ConnectApi.TextSegmentInput();
8
9messageBodyInput.messageSegments = new List<ConnectApi.MessageSegmentInput>();
10
11textSegmentInput.text = 'Does anyone in this group have an idea? ';
12messageBodyInput.messageSegments.add(textSegmentInput);
13
14mentionSegmentInput.id = '0F9D00000000oOT';
15messageBodyInput.messageSegments.add(mentionSegmentInput);
16
17commentInput.body = messageBodyInput;
18
19ConnectApi.Comment commentRep = ConnectApi.ChatterFeeds.postCommentToFeedElement(communityId, feedElementId, commentInput, null);