Have you ever tried to look for Salesforce Actions in google? Unless you are completely sure what you are looking for, you can be lost reading many entries that talk about different features.
This new post will cover these points and also show examples using them.
- Global Actions variables
- Action attributes on Visualforce pages
- Chatter Actions
- Quick Actions
- Invocable Actions with APIs
-
Global Action variable $Action
Global variables help you to show general information about the current user and the organization. They are used on Visualforce pages, with the syntax {$GlobalVariable.Value}
But here, we will focus on the Action one, that allows you to refer Standard Actions related to an object like create, edit, update or delete. For instance, this piece of code will show a link in a page that goes to a New Account Standard UI page:
<apex:page>
<apex:outputLink value="{!URLFOR($Action.Account.New)}">
Create New Account
</apex:outputLink>
</apex:page>
-
Action attributes on Visualforce pages
We can continue talking about actions on visualforce pages. When we want to do something after clicking on a button, we must define an action there. How? Just adding the action attribute on the tag. For instance, bellow code is a visualforce page that allows you create a new Account record after entering its Name and clicking on the save button that the tag <apex:commandButton> shows
.
<apex:page standardController="Account">
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="Save Account" action="{!save}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection >
<apex:inputField value="{!Account.Name}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Remember that in order to show this page you only need to add /apex/<yourpagename> to the url:
https://<instance>.visual.force.com/apex/<yourpagename>
And this is an example of the result:
Chatter Actions allow you to do something on an object via chatter. What does it mean? On Chatter, apart from the common actions like Comment, Link, Post, etc, we can create some others in order to perform a new action quickly. As you can see on Salesforce help, there are different actions, and here, I will create a custom action related to the Account standard object.
Tip: remember to have chatter enabled
Steps are:
1. Go to Setup | App Setup | Customize | Accounts | Buttons, Links and Actions and create a new Action in order to create an Opportunity related to the Account
2. Include in the Page Layout those fields that you want to populate during the Opportunity creation
3. Add the new Quick Action into your chatter post.
These images shows above steps:
4. Open your Account and select the new Quick Action.
5. Populate Opportunity fields with the information and click save
6. A new Opportunity and a chatter post on Account record are created
Like previous point, Quick Actions will allow you to perform an action faster than usual in Salesforce. One of the main differences is that Quick Actions help you defining a global action in the org and you will be able to run it from your User chatter post instead of just the post related to a record.
Salesforce already provides Quick Actions for Standard objects, so my action will allow me to create a new custom object record, Trip Request.
Tip: remember to have chatter enabled
Steps are:
1. Go to Setup | App Setup | Create | Global Actions | Actions In a similar way as before, define the new action.
2. Include in the Page Layout those fields that you want to populate during the Trip Request creation
3. Add the new Quick Action into the chatter post.
4. In order to run it, you just need to go to your chatter feed:
or you can also run it from your SF1 mobile app
5. Populate Trip Request fields with the information and click save
6. A new Trip Request and a chatter post related to your user record are created
If someone talk about Invocable Actions, we could think that is something more difficult than what it is actually.
As you can see in the help, via REST API we are able to get all actions that we can find in the org and can be called by API.
Tip: bellow examples are run via Salesforce Workbench
An easy example is to execute this line on Workbench:
/services/data/v33.0/actions
Tip: It is available only via REST API 32.0 onwards
What do we get? All actions, custom and standard one.
Workbench also allows us to navigate across the options, and in this way we can see how under custom we can find the 2 actions we have created on above sections:
The one related to Account that creates Opportunities:
And the Quick Action that creates Trip Requests: