インライン画像を含むリッチテキストコメントの投稿
インライン画像とメンションを含むリッチテキストコメントを投稿する方法は 2 つあります。GitHub の ConnectApiHelper リポジトリを使用して 1 行のコードを記述するか、postCommentToFeedElement(communityId, feedElementId, comment, feedElementFileUpload) をコールする次の例を使用します。この例の画像ファイルは、Salesforce にアップロード済みの既存のコンテンツです。
1String communityId = null;
2String feedElementId = '0D5R0000000SBEr';
3String imageId = '069R00000000IgQ';
4String mentionedUserId = '005R0000000DiMz';
5
6ConnectApi.CommentInput input = new ConnectApi.CommentInput();
7ConnectApi.MessageBodyInput messageInput = new ConnectApi.MessageBodyInput();
8ConnectApi.TextSegmentInput textSegment;
9ConnectApi.MentionSegmentInput mentionSegment;
10ConnectApi.MarkupBeginSegmentInput markupBeginSegment;
11ConnectApi.MarkupEndSegmentInput markupEndSegment;
12ConnectApi.InlineImageSegmentInput inlineImageSegment;
13
14messageInput.messageSegments = new List<ConnectApi.MessageSegmentInput>();
15
16
17markupBeginSegment = new ConnectApi.MarkupBeginSegmentInput();
18markupBeginSegment.markupType = ConnectApi.MarkupType.Bold;
19messageInput.messageSegments.add(markupBeginSegment);
20
21textSegment = new ConnectApi.TextSegmentInput();
22textSegment.text = 'Hello ';
23messageInput.messageSegments.add(textSegment);
24
25mentionSegment = new ConnectApi.MentionSegmentInput();
26mentionSegment.id = mentionedUserId;
27messageInput.messageSegments.add(mentionSegment);
28
29textSegment = new ConnectApi.TextSegmentInput();
30textSegment.text = '!';
31messageInput.messageSegments.add(textSegment);
32
33markupEndSegment = new ConnectApi.MarkupEndSegmentInput();
34markupEndSegment.markupType = ConnectApi.MarkupType.Bold;
35messageInput.messageSegments.add(markupEndSegment);
36
37inlineImageSegment = new ConnectApi.InlineImageSegmentInput();
38inlineImageSegment.altText = 'image one';
39inlineImageSegment.fileId = imageId;
40messageInput.messageSegments.add(inlineImageSegment);
41
42input.body = messageInput;
43
44ConnectApi.ChatterFeeds.postCommentToFeedElement(communityId, feedElementId, input, null);