Inside Action Link Templates

In this blog post,  I am going to give an overview of the Action Link Templates and its conceptual knowledge. Action link is a button with some action on a feed element which is having a capability to a redirect Web page, initiate a file download, or invoke an API call to Salesforce or to an external server  like  when you want to post a survey link to Salesforce chatter feed or you wanted to approve or reject travel or expense from the chatter feed are few use cases of action link templates .

Terminology:-  

Action Links: – An action link is a button on a feed element. Clicking an action link can take a user to a  Web page, initiate a file download, or invoke an API call to Salesforce or to an external server. Action links on chatter post can allow you to integrate your chatter feed with Salesforce and third-party services into the feed.

Action Link Templates: –  Action like the template is the place when you can define your server-side execute logic decoratively by using context variables and binding variables. You can use template binding keys in the Action URL, HTTP Request Body, and HTTP headers fields to make an API call. Suppose on click on button user need to send an SMS from the feed, in this case, you can defined the URL to send SMS and body and Header and other authentication parameters in Action link template by using binding variables and context variables.you can specify  binding variables in the template at the time of  instantiate the action link group. You can also specify context variables in the templates like who is executes the action link, Salesforce provides values for these variables, such as who executed the link and in which organization

Action Link Group Template: – To associate an action link with a feed element, you need to create an action link group template which is a collection of Action link templates. With the action link group template, you can able to control the Action links location on chatter feed like primary or overflow.

Types of Action Link: –

With Action link template you can choose the different type of action as describes below .you can specify the action link type in the action-type property when you define an action link.

Api—The action link calls a synchronous API at the action URL.

For example Approve Expenses, Travel request.

ApiAsync—The action link calls an asynchronous API at the action URL.

For example  Upload Files, send SMS etc

Download—The action link downloads a file from the action URL.

For example Download file from Dropbox, Box, etc.

Ui—The action link takes the user to a Web page to the action URL.

For example View Map, open Visual Force Page, Canvas Page, etc.

Action link appearance: – While designing you action link templates you can specify the chatter feed item location by using Category property. it can be one of  Primary or Overflow.

If you specify the Category as Primary then action link will appear on Feed-item Body

If you specify the Category as  Overflow then Feed-item Detail Menu.

dtxY01494460173

Declarative Binding: –Not always you no need to pass the static data for the action link template while designing .you can identify the key areas where you need to make changes dynamically replace those by using Binding variables or context variables.

Use context variables to pass information about the user who executed the action link and the context in which it was invoked into the HTTP request made by invoking an action link. You can use context variables in the actionUrl, headers, and requestBody properties of the Action Link Definition Input request body or ConnectApi.ActionLinkDefinitionInput object.

Use binding variables in templates and set their values when you instantiate an action link group. Use binding variables to add sensitive information at run time.  You can define binding variables in the Action URL, HTTP Request Body, and HTTP Headers fields of an action link template. After a template is published, you can edit these fields, you can move binding variables between these fields, and you can delete binding variables. However, you can’t add new binding variables. Define a binding variable’s key in the template. When you instantiate the action link group, specify the key and its value.

Action link URL  with Bindings

https://www.example.com/{!Bindings.ApiVersion}/items/{!Bindings.ItemId}

Action Link Header with Bindings

The lifetime of Action links: –  Setting up expiration data on action link template is easy to maintain suppose let’s consider you are posting a survey link to feed that should be available only specific time. these type of requirements you can set with hours until expiration value. The expiration date can be calculated based on a period provided in the template, or the action link group can be set not to expire at all. To set the hours until expiration in a template, enter a value in the Hours until Expiration field of the action link group template. This value is the number of hours from when the action link group is instantiated until it’s removed from associated feed elements and can no longer be executed. The maximum value is 8760, which is 365 days.

Who can Execute and how many times?

Choose a value from the User Visibility drop-down list to determine who can see the action link after it’s associated with a feed element. Among the available options are Only Custom User Can See and Everyone Except Custom User Can See. Choose one of these values to allow only a specific user to see the action link or to prevent a specific user from seeing it. Then enter a value in the Custom User Alias field. This value is a binding variable key. In the code that instantiates the action link group, use the key and specify the value as you would for any binding variable. You can decide how many time each user wanted to execute action link by setting execution allowed with any one of values as unlimited, Once Per User, Once.

 

 

 

Posting Survey Link to Feed with Action Link Template

1 Introduction

In this blog, I am going to explain how to set up survey link to the chatter feed by using action link template.Here we are going to use Action Link Template Action type “UI”.UI Action will take the user to a Web page to the action URL. Here I am using SurveyMonkey survey link URL.

Please refer this link for more information on Action link templates Inside Action Link Templates

2 Create the Action Link Templates

Action link templates is a group of Actions that is going to be associated with the chatter feed. To create an Action link template From Setup, enter Action Link Templates in the Quick Find box, then select Action Link Templates. Click on New button then add the values in a new Action Link Group Template as shown below then save it.

Name Complete Survey
Developer Name Complete_Survey
Category Primary action
Executions Allowed Once per User

2

Now you create an Action Link Group Template . after that you can associate one or more action link templates.The action link template is automatically associated with an action link group template in a master-detail relationship. Add new action link template under the Action Link group template as shown below.

3.PNG

Action Type: UI
Action URL  https://www.surveymonkey.com/r/{!Bindings.surveylinkId}
User Visibility Everyone can see
Position 0
Label Key – none
HTTP Method GET
Label: Complete Survey

Now go to Action Link Group Template Detail Click on Edit then Check “Published” checkbox checked and save it. So that you can instantiate action line template group

3 . Get the Action Link Group Template ID

You need to get the previously defined action link template group Id. You can get in different ways like SOQL, Rest API or you can take from the URL. Action Link Template Group Object is Queriable so you can use simple SOQL as shown below

SELECT id FROM ActionLinkGroupTemplate WHERE DeveloperName=’Complete_Survey’

4.PNG

4 Instantiate the Action Link Group

You can instantiate the action link group by Using rest API or Apex Code. But in this case, I am using rest API along with workbench for rest API.

Login into workbench by using https://workbench.developerforce.com/logout.php URL. Go to Utilities -> rest explorer
End Point URL :- /services/data/v39.0/connect/action-link-group-definitions
Select operation as POST and Use the Body as shown below

 

If you can see above JSON is contacting the Action Linke Group Template Id and the array of TemplateBindings.  template bindings are contained key and values. Key should match with the action link template bindings variable reference and values is the corresponding values.{!Bindings.surveylinkId} === >  {

{!Bindings.surveylinkId} === >  {
“key”:”surveylinkId”,
“value”:”M6DQ2WD”
}

5

Click  on Execute now after that you see the JSON response as shown below which contains Action link id which you need to pass the Feed Element in next step

7.PNG

5 . Associate the Action Link Group with a Feed Element and Post It

Now in this step, you are going to create chatter feed and posting to the chatter. You can do it by using apex or rest API. here I am going to use rest API with workbench again.

Go to Utilities -> rest explorer
End Point URL :-/services/data/v39.0/chatter/feed-elements
Select operation as POST and Use the Body as shown below.

 

 

Now you can see the above request body contains action link group id instance which you got in earlier steps.

8.PNG

 

Click on Execute now. It will create a  new chatter feed post with action links as shown below.

9.PNG

On lick on of Complete Survey button, it will take you to the Survey link URL.

 

 

Salesforce Apex Setup Audit trail

Starting with Winter ’16, Salesforce allowing access Setup Audit Trail object via API. Which is having access audit trail data more than 6 months but no official confirmation on how much you can go into history

SetupAuditTrail is not a supported standard controller. Its support only queries and retrieve API calls.
You can use SOQL joins to get the information you need more quickly. For example, running SELECT CreatedBy.Name FROM SetupAuditTrail returns the first and last names of the people to make changes in Setup.
You can use where Cause and Order By Cause to perform an operation on data retrieval.
SELECT CreatedDate, CreatedBy.Username, Display, Section, Action, DelegateUser FROM SetupAuditTrail WHERE CreatedDate >= 2016-09-10T00:00:00Z AND CreatedDate <= 2016-10-01T00:00:00Z ORDER BY CreatedDate DESC.
Aggregate queries aren’t supported on SetupAuditTrail object.
Fields Supported: –
SetupAuditTrail Objects supports these fields namely Action, DelegateUser, Display, Section,
Examples: –
List listAudits = [SELECT Id,  Action, CreatedBy.Name, CreatedDate,Display,Section FROM SetupAuditTrail WHERE CreatedBy.Email LIKE ‘%abc.com%’];
Another Example with Last few years information.
            SELECT Id,Action,CreatedBy.Name,CreatedDate,Display,Section FROM SetupAuditTrail WHERE CreatedDate = LAST_N_YEARS:8 Order By CreatedDate DESC   Limit 10
Here is the visual force page UI

Here is Github URL for the complete example.

https://github.com/rajamohanvakati/SetupAuditTrail