Actions are Salesforce’s general term for tasks users can perform either through buttons throughout various UI’s on desktop, mobile, tablet etc or in fact via non-UI processes such those built via via Process Builder or Automation Flows.
Actions are about “getting things done” in Salesforce. They encapsulate a piece of logic that allows a user to perform some work, such as sending email. When an action runs, it saves changes in your organization by updating the database. More here.
Over the years we’ve had many terms and ways to define these. Custom Button and Custom Link are perhaps the most obvious ones, which i’ve covered here in the past. Quick Actions (previously Publisher Actions) and more recently we’ve had Action Link‘s, which i covered in a past blog. Then of course the Standard Buttons, Edit, Delete, Follow, Submit for Approval etc provided by the platform. Such actions appear in various places Record layouts, List Views, Related Lists, Chatter and more recently Flexi Pages (aka Lighting Pages).
You might wonder then, if you had the task as developer to build your own UI or tool that wanted to expose some or all of the above actions, it would be quite a challenge to find them all. Indeed in some cases you may have had to resort to URL hacking to invoke some of them. Well worry not no longer, Salesforce’s clever architects now have you covered! Enter a new virtual SObject known as PlatformAction! Before we get onto what exactly virtual means, lets review some Actions and some SOQL queries…
Consider this Account Record detail page in the Classic (or Aloha) UI…
Note down your record ID and use it in a query like the one below…
SELECT DeviceFormat, Label, Type, Section, ActionTarget, ActionTargetType, ActionListContext FROM PlatformAction WHERE ActionListContext = 'Record' AND SourceEntity = '001B000000D2V0n' AND Section = 'Page' AND DeviceFormat = 'Aloha'
In Developer Console you should see something like this…
Pretty cool huh!? Check out the ActionTarget field, for the Standard Button records, thats the URL you can place on your UI’s to invoke that action, simple as that! Better still this is a supported way to get it, no more URL hacking! Now lets add a couple of Custom Buttons and re-run the query…
We now see CustomButton records appear…
This next query reveals actions shown on a List View. I did note Custom List View buttons that require record selection did not appear however. I suspect this is due to them requiring more than a simple HTTP GET URL to invoke.
SELECT DeviceFormat, Label, Type, Section, ActionTarget, ActionTargetType, ActionListContext FROM PlatformAction WHERE ActionListContext = 'ListView' AND SourceEntity = 'Account' AND Section = 'Page' AND DeviceFormat = 'Aloha'
- Prior to Summer’16 (out in preview as i write this), Apex SOQL was not supported, only REST API SOQL. This is due to a limitation with the internally applied LIMIT keyword. This has now been resolved in Summer’16, so Apex SOQL now works!
- SourceEntity can also be given an SObject API name, e.g. SourceEntity = ‘Account’, the result here are object level buttons, like New or those you add to the MRU page.
- DeviceFormat field value matters, if you leave it off, it defaults to Phone. Thus some actions will be missing from those in Desktop (Lightning Experience) or Aloha (Classic). I eventually found Custom Buttons using Visualforce pages that didn’t have the Lightning Supported checkbox set didn’t appear when querying with the Phone device type for example.
- User context matters, actions returned are user and configuration sensitive, meaning the record itself, record type and associated layout all contribute to the actions returned. Custom Buttons for example need to be on the relevant layout.
- Label and Icon information, there are also fields that allow you to render appropriate labels and icons for the actions.
- Related List actions, you can also retrieve actions shown on related lists, search for RelatedList in the help topic here.
- Describe actions? You will notice some actions have an ActionTargetType of Describe? These are invoked via an API, something i will cover in later blog.
So lets discuss the “virtual SObject” bit!?!
Your probably wondering what a virtual SObject is?
Well my best guess is its an SObject that is not backed by physical data in the Salesforce database. If you check the documentation you’ll see fields just like any other object and it supports SOQL (with some limitations). My thinking is the records for this object are dynamically generated on demand by doing all the heavy lifting internally to scan all the various historic places where actions have been defined.
Thank you Salesforce architects, this is now my #1 coolest Salesforce API!
- For starters, no more URL hacking of those standard pages, no excuses now!
- Helper class or Visualforce and/or Lighting component for actions?
- Explore the Force.com Actions Developer Guide