新しい (バイナリ) ファイルを添付したフィード要素の一括投稿
このトリガは postFeedElementBatch(communityId, feedElements) メソッドをコールして、新たに挿入された取引先のフィードに一括投稿します。各投稿に新しい (バイナリ) ファイルが添付されます。
1swfobject.registerObject("clippy.codeblock-0", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17trigger postFeedItemToAccountWithBinary on Account (after insert) {
18 Account[] accounts = Trigger.new;
19
20 // Bulk post to the account feeds.
21
22 List<ConnectApi.BatchInput> batchInputs = new List<ConnectApi.BatchInput>();
23
24 for (Account a : accounts) {
25 ConnectApi.FeedItemInput input = new ConnectApi.FeedItemInput();
26
27 input.subjectId = a.id;
28
29 ConnectApi.MessageBodyInput body = new ConnectApi.MessageBodyInput();
30 body.messageSegments = new List<ConnectApi.MessageSegmentInput>();
31
32 ConnectApi.TextSegmentInput textSegment = new ConnectApi.TextSegmentInput();
33 textSegment.text = 'Let\'s win the ' + a.name + ' account.';
34
35 body.messageSegments.add(textSegment);
36 input.body = body;
37
38 ConnectApi.ContentCapabilityInput contentInput = new ConnectApi.ContentCapabilityInput();
39 contentInput.title = 'Title';
40
41 ConnectApi.FeedElementCapabilitiesInput capabilities = new ConnectApi.FeedElementCapabilitiesInput();
42 capabilities.content = contentInput;
43
44 input.capabilities = capabilities;
45
46 String text = 'We are words in a file.';
47 Blob myBlob = Blob.valueOf(text);
48 ConnectApi.BinaryInput binInput = new ConnectApi.BinaryInput(myBlob, 'text/plain', 'fileName');
49
50 ConnectApi.BatchInput batchInput = new ConnectApi.BatchInput(input, binInput);
51
52 batchInputs.add(batchInput);
53 }
54
55 ConnectApi.ChatterFeeds.postFeedElementBatch(Network.getNetworkId(), batchInputs);