Example: Define Template Action Links

This example creates an action link template, instantiates the action link group, and associates the action link group with a feed element and posts the 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 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 Connect 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.

  1. From Setup, enter Action Link Templates in the Quick Find box, then select Action Link Templates.

  2. Use these values in a new Action Link Group Template:

    FieldValue
    NameDoc Example
    Developer NameDoc_Example
    CategoryPrimary action
    Executions AllowedOnce per User
  3. Use these values in a new Action Link Template:

    FieldValue
    Action Link Group TemplateDoc Example
    Action TypeApi
    Action URL/services/data/{!Bindings.ApiVersion}/chatter/feed-elements
    User VisibilityEveryone can see
    HTTP Request Body{"subjectId": "{!Bindings.SubjectId}","feedElementType": "FeedItem","body": {"messageSegments": [{"type": "Text","text": "{!Bindings.Text}"}]}}
    HTTP HeadersContent-Type: application/json
    Position0
    Label KeyPost
    HTTP MethodPOST
  4. 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/v67.0/query?q=SELECT+id+FROM+ActionLinkGroupTemplate+WHERE+DeveloperName='Doc_Example'

cURL example 

1curl https://{instanceName}/services/data/v67.0/query?q=SELECT+id+FROM+ActionLinkGroupTemplate+
2WHERE+DeveloperName='Doc_Example' -H "Authorization: Bearer {accessToken}"

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/v67.0/sobjects/ActionLinkGroupTemplate/07gD00000004CEhIAM"
9         },
10         "Id":"07gD00000004CEhIAM"
11      }
12   ]
13}

Step 3: Instantiate the Action Link Group 

Use the action link group template ID to instantiate the action link group.

Resource 

/connect/action-link-group-definitions

HTTP method 

POST

Request body 

Action Link Group Definition Input

This Action Link Group Definition Input request body includes a templateBindings property that is a collection of Action Link Template Binding Input request bodies. In this example, the Action Link Template Binding Input request body includes three template bindings.

Request body example 

1POST /services/data/v67.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":"v67.0" },
3{ "key":"Text", "value":"This post was created by an API Action Link!" }, { "key":"SubjectId", "value":"me" } ] }'
4 -X POST "https://{instanceName}/services/data/v67.0/connect/action-link-group-definitions"
5 -H 'Authorization: OAuth 00DRR0000000N0g!RWaPj94O6yOD.lfjB9LqMk' --insecure

Response body 

Action Link Group Definition

Step 4: Post a Feed Element 

Associate the action link group with a feed element and post it. You can associate up to 10 action link groups with a feed element.

Resource 

/chatter/feed-elements

HTTP method 

POST

Request body 

Feed Item Input

This Feed Item Input request body includes a body property that is a Message Body Input request body. In this example, the Message Body Input request body includes a messageSegments property that has one Message Segment Input: Text request body.

This Feed Item Input request body also includes a capabilities property that is a Feed Element Capabilities Input request body. In this example, the Feed Element Capabilities Input includes an associatedActions property that is a Associated Actions Capability Input request body.

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/v67.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://{instanceName}/services/data/v67.0/chatter/feed-elements" -H 'Authorization: OAuth {accessToken}' --insecure

Response body 

Feed Item

See Also