Newer Version Available

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

Define an Action Link and Post with a Feed Element

This example creates one action link in an action link group, associates the action link group with a feed item, and posts the feed item. Action link on a feed item in the feed.

When a user clicks the action link, the action link requests the Chatter REST API resource /chatter/feed-elements, which posts a feed item to the user’s feed. After the user clicks the action link and it executes successfully, its status changes to successful and the feed item UI is updated:Successfully executed action link.Refresh the user’s feed to see the new post:Post created by an action link.This is a simple example, but it shows you how to use action links to make a call to a Salesforce resource.

Think of an action link as a button on a feed item. Like a button, an action link definition includes a label (labelKey). An action link group definition also includes other properties like a URL (actionUrl), an HTTP method (method), and an optional request body (requestBody) and HTTP headers (headers).

When a user clicks this action link, an HTTP POST request is made to a Chatter REST API resource, which posts a feed item to Chatter. The requestBody property holds the request body for the actionUrl 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.

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.

This example calls ConnectApi.ActionLinks.createActionLinkGroupDefinition(communityId, actionLinkGroup) to create an action link group definition.

It saves the action link group ID from that call and associates it with a feed element in a call to ConnectApi.ChatterFeeds.postFeedElement(communityId, feedElement, feedElementFileUpload).

To use this code, substitute an OAuth value for your own Salesforce organization. Also, verify that the expirationDate is in the future. Look for the To Do comments in the code.

If the post fails, check the OAuth ID.

Note