Newer Version Available

This content describes an older version of this product. View Latest

Post a Batch of Feed Elements

This trigger calls the postFeedElementBatch(communityId, feedElements) method to bulk post to the feeds of newly inserted accounts.
1swfobject.registerObject("clippy.codeblock-0", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17trigger postFeedItemToAccount 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.BatchInput batchInput = new ConnectApi.BatchInput(input);
39        batchInputs.add(batchInput);
40    }
41
42    ConnectApi.ChatterFeeds.postFeedElementBatch(Network.getNetworkId(), batchInputs);
43}