Newer Version Available

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

Define an Action Link in a Template and Post with a Feed Element

This example creates the same action link and action link group as the example Define an Action Link and Post with a Feed Element, but this example instantiates the action link group from a template.

Step 1: Create the Action Link Templates

  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:
    Field Value
    Name Doc Example
    Developer Name Doc_Example
    Category Primary action
    Executions Allowed Once per User
  3. 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
  4. Go back to the Action Link Group Template and select Published. Click Save.

Step 2: Instantiate the Action Link Group, Associate it with a Feed Item, and Post it

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

It calls ConnectApi.ChatterFeeds.postFeedElement(communityId, feedElement) to associate the action link group with a feed item and post it.