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