Newer Version Available
Define Action Links in a Template and Post with a Feed Element
Step 1: Create the Action Link Templates
Just like radio buttons, action links must be nested in a group. Action links within a group share the properties of the group and are mutually exclusive (you can click on only one action link within a group). Even if you define only one action link, it must be part of an action link group. The same is true for action link templates and action link group templates.
This example uses one action link in an action link group. When a user clicks the action link, an HTTP POST request is made to a Chatter REST API resource, which posts a feed item to Chatter. The HTTP Request Body field holds the request body for the Action URL resource, including the text of the new feed item. In this example, the new feed item includes only text, but it could include other capabilities such as a file attachment, a poll, or even action links.
- From Setup, enter Action Link Templates in the Quick Find box, then select Action Link Templates.
- Use these values in a new Action Link Group Template:
Field Value Name Doc Example Developer Name Doc_Example Category Primary action Executions Allowed Once per User - Use these values in a new Action Link Template:
Field Value Action Link Group Template Doc Example Action Type Api Action URL /services/data/{!Bindings.ApiVersion}/chatter/feed-elements User Visibility Everyone can see HTTP Request Body {"subjectId": "{!Bindings.SubjectId}","feedElementType": "FeedItem","body": {"messageSegments": [{"type": "Text","text": "{!Bindings.Text}"}]}} HTTP Headers Content-Type: application/json Position 0 Label Key Post HTTP Method POST - Go back to the Action Link Group Template and select Published.
Click Save.
Make a note of the Action Link Group Template ID and skip to Step 3.
Step 2: Get the Action Link Group Template ID
If you have access to the action link group template in Setup, you can get the Action Link Group Template ID and skip to Step 3.
- Resource
-
1/services/data/v33.0/query - HTTP method
- GET
- Request parameters
- q—A SOQL query string.
- Request parameters example
-
1GET /services/data/v35.0/query?q=SELECT+id+FROM+ActionLinkGroupTemplate+WHERE+DeveloperName='Doc_Example' - cURL example
-
1curl https://na1.salesforce.com/services/data/v35.0/query?q=SELECT+id+FROM+ActionLinkGroupTemplate+ 2WHERE+DeveloperName='Doc_Example' -H "Authorization: Bearer token" - Response body
- An array of query result records.
-
1{ 2 "totalSize":1, 3 "done":true, 4 "records":[ 5 { 6 "attributes":{ 7 "type":"ActionLinkGroupTemplate", 8 "url":"/services/data/v35.0/sobjects/ActionLinkGroupTemplate/07gD00000004CEhIAM" 9 }, 10 "Id":"07gD00000004CEhIAM" 11 } 12 ] 13}
Step 3: Instantiate the Action Link Group
- Resource
- /connect/action-link-group-definitions
- HTTP method
- POST
- Request body
- Action Link Group Definition Input
- Request body example
-
1POST /services/data/v35.0/connect/action-link-group-definitions 2{ 3 "templateId":"07gD00000004CEhIAM", 4 "templateBindings" : [ 5 { 6 "key":"ApiVersion", 7 "value":"v33.0" 8 }, 9 { 10 "key":"Text", 11 "value":"This post was created by an API Action Link!" 12 }, 13 { 14 "key":"SubjectId", 15 "value":"me" 16 } 17 ] 18} - Request example using cURL
- To use cURL to make the request, enter the following and substitute your Developer
Edition instance name, and OAuth
information.
1curl -H "X-PrettyPrint: 1" -H "Content-Type: application/json" -d '{ "templateId":"07gD00000004CEhIAM", 2"templateBindings" : [ { "key":"ApiVersion", "value":"v35.0" }, 3{ "key":"Text", "value":"This post was created by an API Action Link!" }, { "key":"SubjectId", "value":"me" } ] }' 4 -X POST "https://instance_name/services/data/v35.0/connect/action-link-group-definitions" 5 -H 'Authorization: OAuth 00DRR0000000N0g!RWaPj94O6yOD.lfjB9LqMk' --insecure - Response body
- Action Link Group Definition
Step 4: Associate the Action Link Group with a Feed Element and Post It
- Resource
- /chatter/feed-elements
- HTTP method
- POST
- Request body
- Feed Item Input
- Request body example
-
Grab the action link group ID from the id property of the Action Link Group Definition response from step 3.
1POST /services/data/v35.0/chatter/feed-elements 2 3{ 4 "body": { 5 "messageSegments": [ 6 { 7 "type": "Text", 8 "text": "Click to post a feed item." 9 } 10 ] 11 }, 12 "subjectId": "me", 13 "feedElementType": "feedItem", 14 "capabilities": { 15 "associatedActions": { 16 "actionLinkGroupIds": ["0AgRR0000004CTr0AM"] 17 } 18 } 19} - Request example using cURL
- To use cURL to make the request, enter the following and
substitute the action link group ID returned in step 2, your Developer Edition instance
name, and your OAuth
information.
1curl -H "X-PrettyPrint: 1" -H "Content-Type: application/json" -d '{ "body": { "messageSegments": [ { "type": "Text", "text": "Click to post a feed item." } ] }, "subjectId": "me", "feedElementType": "feedItem", "capabilities": { "associatedActions": { "actionLinkGroupIds": ["0AgRR0000004CTr0AM"] } } }' -X POST "https://instance_name/services/data/v35.0/chatter/feed-elements" -H 'Authorization: OAuth OOARoAQETAKEIddnMWXh462dprYAgRWaPj94O6yOD' --insecure - Response body
- Feed Item