No Results
Search Tips:
- Please consider misspellings
- Try different search keywords
テンプレートのアクションリンクを定義し、フィード要素を使用して投稿する
この例では、アクションリンクを定義し、フィード要素を使用して投稿するの例と同じアクションリンクとアクションリンクグループを作成しますが、テンプレートからアクションリンクグループをインスタンス化します。
ステップ 1: アクションリンクテンプレートを作成する
- [設定] で、 をクリックします。
- 新しいアクションリンクグループテンプレートで次の値を使用します。
項目 値 名前 ドキュメントの例 開発者名 Doc_Example カテゴリ プライマリアクション 実行可 ユーザごとに 1 回 - 新しいアクションリンクテンプレートで次の値を使用します。
項目 値 アクションリンクグループテンプレート ドキュメントの例 アクションの種類 Api アクション URL /services/data/{!Bindings.ApiVersion}/chatter/feed-elements ユーザ表示設定 全員に表示 HTTP リクエストボディ {"subjectId": "{!Bindings.SubjectId}","feedElementType": "FeedItem","body": {"messageSegments": [{"type": "Text","text": "{!Bindings.Text}"}]}} HTTP ヘッダー Content-Type: application/json 位置 0 表示ラベルキー 投稿 HTTP メソッド POST - アクションリンクグループテンプレートに戻り、[公開済み] を選択します。[保存] をクリックします。
ステップ 2: アクションリンクグループをインスタンス化し、フィード項目に関連付けて投稿する
この例では、ConnectApi.ActionLinks.createActionLinkGroupDefinition(String, ConnectApi.ActionLinkGroupDefinitionInput) をコールしてアクションリンクグループ定義を作成します。
ConnectApi.ChatterFeeds.postFeedElement(String, ConnectApi.FeedElementInput, ConnectApi.BinaryInput) をコールしてアクションリンクをフィード項目に関連付けて投稿します。
1swfobject.registerObject("clippy.codeblock-0", "9");// Get the action link group template Id.
2ActionLinkGroupTemplate template = [SELECT Id FROM ActionLinkGroupTemplate WHERE DeveloperName='Doc_Example'];
3
4// Add binding name-value pairs to a map.
5// The names are defined in the action link template(s) associated with the action link group template.
6// Get them from Setup UI or SOQL.
7Map<String, String> bindingMap = new Map<String, String>();
8bindingMap.put('ApiVersion', 'v33.0');
9bindingMap.put('Text', 'This post was created by an API action link.');
10bindingMap.put('SubjectId', 'me');
11
12// Create ActionLinkTemplateBindingInput objects from the map elements.
13List<ConnectApi.ActionLinkTemplateBindingInput> bindingInputs = new List<ConnectApi.ActionLinkTemplateBindingInput>();
14
15for (String key : bindingMap.keySet()) {
16 ConnectApi.ActionLinkTemplateBindingInput bindingInput = new ConnectApi.ActionLinkTemplateBindingInput();
17 bindingInput.key = key;
18 bindingInput.value = bindingMap.get(key);
19 bindingInputs.add(bindingInput);
20}
21
22// Set the template Id and template binding values in the action link group definition.
23ConnectApi.ActionLinkGroupDefinitionInput actionLinkGroupDefinitionInput = new ConnectApi.ActionLinkGroupDefinitionInput();
24actionLinkGroupDefinitionInput.templateId = template.id;
25actionLinkGroupDefinitionInput.templateBindings = bindingInputs;
26
27// Instantiate the action link group definition.
28ConnectApi.ActionLinkGroupDefinition actionLinkGroupDefinition =
29 ConnectApi.ActionLinks.createActionLinkGroupDefinition(Network.getNetworkId(), actionLinkGroupDefinitionInput);
30
31ConnectApi.FeedItemInput feedItemInput = new ConnectApi.FeedItemInput();
32ConnectApi.FeedElementCapabilitiesInput feedElementCapabilitiesInput = new ConnectApi.FeedElementCapabilitiesInput();
33ConnectApi.AssociatedActionsCapabilityInput associatedActionsCapabilityInput = new ConnectApi.AssociatedActionsCapabilityInput();
34ConnectApi.MessageBodyInput messageBodyInput = new ConnectApi.MessageBodyInput();
35ConnectApi.TextSegmentInput textSegmentInput = new ConnectApi.TextSegmentInput();
36
37// Define the FeedItemInput object to pass to postFeedElement
38feedItemInput.body = messageBodyInput;
39feedItemInput.capabilities = feedElementCapabilitiesInput;
40feedItemInput.subjectId = 'me';
41
42// The MessageBodyInput object holds the text in the post
43messageBodyInput.messageSegments = new List<ConnectApi.MessageSegmentInput>();
44
45textSegmentInput.text = 'Click to post a feed item.';
46messageBodyInput.messageSegments.add(textSegmentInput);
47
48
49// The FeedElementCapabilitiesInput object holds the capabilities of the feed item.
50// For this feed item, we define an associated actions capability to hold the action link group.
51// The action link group ID is returned from the call to create the action link group definition.
52feedElementCapabilitiesInput.associatedActions = associatedActionsCapabilityInput;
53associatedActionsCapabilityInput.actionLinkGroupIds = new List<String>();
54associatedActionsCapabilityInput.actionLinkGroupIds.add(actionLinkGroupDefinition.id);
55
56// Post the feed item.
57ConnectApi.FeedElement feedElement = ConnectApi.ChatterFeeds.postFeedElement(Network.getNetworkId(), feedItemInput, null);