新しいファイルを添付したコメントの投稿
新しいファイルを添付したコメントを投稿するメソッドをコールします。
コメントを投稿し、新しいファイルをアップロードしてコメントに添付するには、ConnectApi.CommentInput オブジェクトと ConnectApi.BinaryInput オブジェクトを作成して postCommentToFeedElement(communityId, feedElementId, comment, feedElementFileUpload) メソッドに渡します。
1String feedElementId = '0D5D0000000KtW3';
2
3ConnectApi.CommentInput commentInput = new ConnectApi.CommentInput();
4
5ConnectApi.MessageBodyInput messageBodyInput = new ConnectApi.MessageBodyInput();
6ConnectApi.TextSegmentInput textSegmentInput = new ConnectApi.TextSegmentInput();
7
8textSegmentInput.text = 'Enjoy this new file.';
9
10messageBodyInput.messageSegments = new List<ConnectApi.MessageSegmentInput>();
11messageBodyInput.messageSegments.add(textSegmentInput);
12commentInput.body = messageBodyInput;
13
14ConnectApi.CommentCapabilitiesInput commentCapabilitiesInput = new ConnectApi.CommentCapabilitiesInput();
15ConnectApi.ContentCapabilityInput contentCapabilityInput = new ConnectApi.ContentCapabilityInput();
16
17commentCapabilitiesInput.content = contentCapabilityInput;
18contentCapabilityInput.title = 'Title';
19
20commentInput.capabilities = commentCapabilitiesInput;
21
22String text = 'These are the contents of the new file.';
23Blob myBlob = Blob.valueOf(text);
24ConnectApi.BinaryInput binInput = new ConnectApi.BinaryInput(myBlob, 'text/plain', 'fileName');
25
26ConnectApi.Comment commentRep = ConnectApi.ChatterFeeds.postCommentToFeedElement(Network.getNetworkId(), feedElementId, commentInput, binInput);