Cloudy with a megaphone next to text that says, "How to Invoke a Flow from a Global Action."

How to Invoke a Flow from a Global Action

By

It’s great that we can invoke a flow from an object-specific action, but what if you need to invoke a flow from a global action? You COULD embed the flow in a Visualforce page; however, if you were to do so, the flow wouldn’t run in the Lightning skin. You’d get the ugly-looking Classic flow screen. That’s not a good user experience (UX).

From a global action, you can invoke a Lightning component; therefore, you can embed a flow in a Lightning component. Awesome!

Now, I know what you’re thinking. Great news, Jen, but I don’t know how to create a Lightning component. I’m not a developer.

Do you know how to copy and paste? If you do, you’ve got this!

Disclaimer: We’re creating a Lightning component, also known as an Aura component. We’re not creating a Lightning web component (LWC), which is newer technology and more performant than a Lightning component. Ideally, we would create a LWC; this would be the better route. However, it would be more labor-intensive as you’d need install a tool like Visual Studio Code (VS Code) and Salesforce Tooling to create and push the LWC to your org. If you have a developer resource, have them create you a LWC instead. For this solution, we’re using the Developer Console to create our Lightning component right in our org.

Let’s walk through a use case at a fictional company, Mochi Cupcakes, with our beloved #AwesomeAdmin Addison Dogster.

The business problem

Addison Dogster is the system administrator at Mochi Cupcakes. Mary Markle is the Director of Sales Manager. Mary’s sales reps would like to access the flow screen Addison is building from anywhere in Salesforce.

The solution

Ideally, Addison would like to invoke flow from a global action, but this is not a current capability. Being the #AwesomeAdmin that Addison is, she was able to solution this requirement by creating a Lightning component that references the flow invoked from a global action.

Animated gif showing a flow invoked from a global action

Addison created and activated her screen flow in her org.

She has the Flow Detail screen for her screen flow handy to grab the Flow API Name, which she will need when she creates the Lightning component.

The Flow Detail page with an arrow pointing to the Flow API Name

Next, she creates a Lightning component using the Developer Console, accessed via the wrench icon in the upper-right header.

Note: The important part for exposing the Lightning component to a global action or quick action is the code “force:lightningQuickActionWithoutHeader”.

Addison copies and pastes the following code in the Component tab. She saves her changes.

<aura:component implements="flexipage:availableForAllPageTypes, flexipage:availableForRecordHome, force:hasRecordId,force:lightningQuickActionWithoutHeader" access="global" >
<aura:handler name="init" value="{!this}" action="{!c.init}" />
<lightning:flow aura:id="flowData" />
</aura:component>

Addison tabs over to the controller and copy and pastes the code below.

({
init : function (component) {
// Find the component whose aura:id is "flowData"
var flow = component.find("flowData");
// In that component, start your flow. Reference the flow’s Unique Name.
flow.startFlow("*FlowName*");
},
})

Addison replaces *FlowName* in the code above with her flow API name so the Lightning component knows which flow to invoke. She saves her changes.

Here is Addison’s updated controller with her flow API name inserted:

({
init : function (component) {
// Find the component whose aura:id is "flowData"
var flow = component.find("flowData");
// In that component, start your flow. Reference the flow’s Unique Name.
flow.startFlow("Create_a_Cupcake_Order");
},
})

Here are the steps for creating the Lightning component.

Animated gif showing how to create the Lightning component in the Developer Console

Don’t forget to save the component and the controller. Voilà! You created your first Lightning component! (Well, kinda.)

Now, Addison needs to create the Global Action. In Setup, she navigates to User Interface | Global Actions.

  • Action Type: Select Lightning Component.
  • Lightning Component: Select the Lightning component you just created.
  • Height: Specify the height in pixels.
  • Label: Provide a name of the global action.
  • Name: This is the API name.

Animated gif showing the creation of a global action

Next, Addison needs to place the action onto the Publisher Layout for it to show up in Global Actions. She navigates to Setup | User Interface | Global Actions | Publisher Layouts. She locates the Create a Cupcake Order action she just created in the previous step and drags it into the section.

Note: You may need to override the predefined actions under the Salesforce Mobile and Lightning Experience Actions section.

Animated gif showing how to add the quick action to the global publisher page layout

That’s it! The action should now appear in the Global Actions section in your org! Addison created a Lightning component that invokes a flow invoked from a global action.

Now, it’s your turn! Give this solution a try in your org.

Resources

Flow Enhancements Summer '24.

Flow Enhancements | Summer ’24 Be Release Ready

Summer ’24 is almost here! Learn more about new Flow Builder enhancements like the Automation App, Action Button (beta), and more, and check out Be Release Ready to discover more resources to help you prepare for Summer ’24.  Want to see these enhancements in action? Salesforce product manager Sam Reynard and I will demo some […]

READ MORE
A Salesforce Admin's Guide to TrailblazerDX 2024.

A Salesforce Admin’s Guide to TrailblazerDX 2024

The Trailblazer community is coming back together on March 6-7, 2024, in San Francisco and on Salesforce+ for TrailblazerDX 2024—join us! Generative artificial intelligence (AI) is revolutionizing application development, creating the most significant shift and opportunities for both admins and developers in decades. At TDX, you’ll learn to supercharge user productivity, automate business processes, and […]

READ MORE
Be Release Ready Spring '24 | The Ultimate Guide to Prompt Builder.

The Ultimate Guide to Prompt Builder | Spring ’24

Artificial intelligence (AI) is not a new concept to Salesforce or to Salesforce Admins. Over the years, Salesforce has empowered admins with a user-friendly interface for the setup and configuration of predictive AI features such as Opportunity Scoring, Lead Scoring, Einstein Bots, and more. The introduction of generative AI in Salesforce brings even more possibilities […]

READ MORE