(Note: This blog post was written for Lightning Experience. There are some Local Actions which can be used in Classic/VisualForce, if using the Lightning Flow Runtime, check out this Developer Salesforce post. It does have some limitations around leveraging the standard Lightning events, but can be used to integrate with some 3rd party systems. Thank you, Benoit Dufourd, Lead Quality Engineer at Salesforce, for noting this.)
I want to give a shout out to David Wu, Senior Software Engineering Manager, Platform at Salesforce, for the assist on this.
Flownatics who create interactive screens in the Cloud Flow Designer in Lightning Experience know that you cannot return the end of the flow to a specific URL or show a message in a modal, until Summer ’18 with the introduction of flow local actions.
What is a flow local action, you ask?
A flow action executes JavaScript by calling a Lightning component’s client-side controller. For example, a local action can look up third-party data without going through Salesforce servers, automatically open another URL, or fire a toast message.
To add local actions to a flow, please make sure that:
- The flow’s type is Screen Flow.
- Users can run the flow only in Lightning runtime. For example, don’t distribute the flow using a Visualforce component.
- Your lightning component should include “lightning:availableForFlowActions” using a component’s client-side controller as an action in a flow. Check out some sample local actions at the Unofficial Lightning Flow site.
- Your flow must be executed from an object Quick Action. It will not work with a custom button.
- Your org has My Domain enabled and deployed.
Here are a few lessons learned from implementing this use case:
- Amp up the power of flow with the use of local actions via lightning components.
- Create a custom metadata type that stores the task information to be pulled into the task record creation step in the flow.
- Learn how to invoke flow from a quick action in Lightning Experience.
- Provide descriptions, where provided, in Salesforce. This may be tedious step, I know, but your future self will thank you when you are trying to remember what you configured or assist other/future admins when troubleshooting or enhancing what was built. This includes variables, the purpose of a flow, what each flow element does, etc.
Business Use Case: Addison Dogster is the system administrator at Universal Containers. Mary Markle is the Director of Operations. Mary asked Addison if can auto-create a task when the “stuff” record’s status is “Completed” and the Operations user clicks on the quick action. After the task is created, Mary would like the user redirected to the newly created task. She also wants to prevent users from using the Quick Action if the record’s status is anything other than “Completed.”
Solution: Being the #AwesomeAdmin that Addison is, Addison’s inclination is to create this declaratively via flow. Prior to Summer ’18, it was not possible to show a modal or redirect a user to a specific location at the end of the flow. However, with the introduction of flow local actions, this is now possible. Hooray!
Addison is able to solution these requirements declaratively using a quick action, custom metadata type to store the task information used for the task creation, flow to automate the process, lightning components (don’t fear – there are unmanaged sample local actions that you can install in your org from the Unofficial Lighting Flow site, no coding needed on your part).
Quick Steps:
Pre-Requisites: You are using Lightning Experience. Also, refer above to the other items that need to exist in your org to use local actions.
1.On the profiles that will be using this functionality, enable the “Run Flows” permission. If you do not take this step, the user will not see the flow Quick Action on the Lightning record page.
2. Addison figured that there will be future needs to create tasks automatically, so rather than “hardcode” the task information in flow and if updates are needed in the future, she does not need to create a new version of the flow, she can manage the task information outside of flow in a custom metadata type. (To learn more about custom metadata types, read this blog post.)
Create a Custom Metadata Type (Custom Code | Custom Metadata Types), click on the “New Custom Metadata Type” button.
A. Provide the label name and label name in plural and save.
Best Practice Tip: Don’t forget to provide a description so you and other/future admins know what this custom metadata type is used for.
B. Create a custom field as a picklist data type to specify the task priority.
Best Practice Tip: Don’t forget to provide a description so you and other/future admins know what this custom metadata type is used for.
C. Create a custom field as a text data type to hold the task subject.
Best practice tip: Don’t forget to provide a description so you and other/future admins know what this custom field is used for.
D. Create a custom number field that will be added to today to specify the task due date.
Best practice tip: Don’t forget to provide a description so you and other/future admins know what this custom field is used for.
E. Now, let’s create the custom metadata type records by clicking on the “Manage Task Information” and create a record for each task information.
In this example, Addison is creating this task metadata type record.
3. Install the following lightning components used in this flow example from the the Unofficial Lightning Flow site.
- ShowToast
- OpenSObject
4. Now, we need to create a flow which will lookup the record’s status field, determine whether the status is completed. If the status was anything other than “Completed,” a error message in a modal will be shown. If the status is “Completed,” then create a task assigned to the current user with the task information from the Task Information custom metadata type and redirect the user to the newly created task.
Go to Setup | Process Automation | Flows in Lightning Experience.
A. First, we are going to create three variables and two formulas.
The recordId (this variable name is reserved by Salesforce) to pass the detail record ID into the flow variable for use.
The variable will store the status of the “stuff” record.
The variable will store the Id of the newly created task record.
The sObject variable will store Task Information custom metadata type record information.
We need a formula field to pull in the current user’s Id – {!$User.Id}.
We need a formula field to determine the task’s activity date based on today’s date plus the number of days from the task information custom metadata type data record.
B. Create a Record Lookup called “Lookup the status” to lookup the status value on the stuff record.
Best practice tip: Don’t forget to provide a description so you and other/future admins know what this record lookup element does.
C. We are going to create a Decision flow element to determine if the status is not completed (i.e. variable varStatus does not equal “Completed.” The default outcome is Completed.
Best practice tip: Don’t forget to provide a description so you and other/future admins know what this decision flow element does.
D. We are going to create a Fast Record Lookup flow element that will query the Task Information custom metadata type where the MasterLabel equals “Stuff.” [Note: if you anticipate longer custom metadata type names (master label has a limited number of characters), I suggest you create a custom text field to store the field to reference.]
Store the record in a sObject variable, sObjVarTaskInformation.
Then, we will store the Priority, Subject and Task Days information.
Best practice tip: Don’t forget to provide a description so you and other/future admins know what this record lookup element does.
E. Next, we will create a Record Create flow element to create a task record with the following fields:
- ActivityDate uses the formula resource {!ActivityDateFormula}
- OwnerId uses the formula resource {!CurrentUserFormula}
- Priority uses the sObject variable field {!sObjVarTaskInformation.Priority__c}
- Subject uses the sObject variable field {!sObjVarTaskInformation.Subject__c}
- WhatId uses variable {!recordId}
Assign the record ID to the variable {!varNewTaskId}.
Best practice tip: Don’t forget to provide a description so you and other/future admins know what this record create element does.
F. Let’s pull in a Local Action showToast and configure the message and type attributes as shown below. This is the modal that will appear when the status is not Completed and the user clicks on the quick action that fires the flow.
Best practice tip: Don’t forget to provide a description so you and other/future admins know what this local action element does.
G. Drag in Local Action OpenSObject and configure the SObject to variable {!recordId} so it redirects the user to the stuff record after showing the toast message.
Best practice tip: Don’t forget to provide a description so you and other/future admins know what this local action element does.
H. Pull in the last Local Action OpenSObject that will take the user to the newly created task record by configuring the SObject to variable {!varNewTaskId}.
Best practice tip: Don’t forget to provide a description so you and other/future admins know what this local action flow element does.
I. Add the subflow Send Flow Fault Email. For instructions on how to create this, go to Step 2 of blog post: Maximize Maintainability With Process Builder and Componentized Visual Workflow.
J. Set your flow starting point. And connect the flow elements and the fault connectors to match the below…
K. Save as and provide the following properties. We’re going to call this flow “Jen Local Action Flow.”
Best practice tip: Provide a description so you and other/future admins know what this flow is used for.
L. Click the “Close” button.
M. On the flows screen, activate the flow.
5. Create the Quick Action. Go to the Object Manager | Stuff | Buttons, Links, and Actions. Click to create a “New Action.” Select the flow you created in Step 4.
Best practice tip: Provide a description so you and other/future admins know what this quick action is used for.
6. Don’t forget to add the Quick Action to the appropriate page layout for it to show. In the Page Layout Editor, locate the quick action under Mobile & Lightning Actions and drag it to the location among the mobile and lightning actions and Save.
Now, before you deploy the changes to Production, don’t forget to test your configuration changes.
- Log in as the intended user.
- Navigate to the stuff record and click on the “Jen Run Flow” quick action.
- Update the status to something other than “Completed” and save.
- Verify a modal is shown with the message provided.
- Update the status to “Completed” and save.
- Verify that a new task is created using the information from the Task Information custom metadata type record and redirects you to the newly created task record.
Deployment Notes/Tips:
- The visual workflow, quick action, page layout change, custom metadata type and its records can be deployed to Production in a change set (or can be deployed using a tool such as Dreamfactory’s Snapshot).
- You will find the flow in a change set under the Flow Definition component type.
- Activate the flow post deployment as it deploys inactive in Production.