Auto-Launched Flow in Salesforce | How to Create Auto-Launched Flow In Salesforce

In Salesforce, the process runs automatically without any manual task in the auto-launched flow.

The auto-launched flow is a sub-flow that is called from other flows, DML operations, if there is any platform event occurs, and process builders.

In this Salesforce Tutorial, we will learn about creating an auto-launched flow in Salesforce. In this article, we will see what an auto-launched flow is and when it can be used. Additionally, we will see how to create an auto-launched flow in Salesforce with the scenario.

Auto-Launched Flow in Salesforce

What is auto-launched flow in Salesforce?

In Salesforce, this flow launches when invoked by Apex, processes, REST API, and more. This autolaunched flow runs in the background.

The auto-launched flow does not require any user interaction. It can be called from other sub-flows, process builders, apex classes, a set schedule, or platform events.

When can we use auto-launched flow in Salesforce?

  • Suppose we have a task to create multiple flows and need the functionality that needs to be performed by all the flows; then, we can use an auto-launched flow as a sub-flow that comprises the functionality required by all flows.
  • The auto-launched flow will run in the background. We can’t use any UI element on this one; it will just execute the logic.
  • The auto-launched flow saves time, and we don’t need to create the same functionality repeatedly. It also helps us build a very simplified flow.

Scenario:

We have a screen flow and a record trigger flow. Now, the requirement is that from both the flows we need to send an email. One option is to send an email from both flows individually by creating an email action on both flows.

Instead of creating an email action on both flows, we can use the auto-launched flow as a sub-flow. On this flow, we will create an email action, and this flow we will invoke from other flow whenever we need.

There are the following prerequisites to creating auto-launched flow in Salesforce:

  • We need a screen flow where we can create a record and then email the user to confirm the account’s creation.
  • But we don’t create email action on the screen flow. We will call sub-flow, which is the auto-launched flow for sending an email.
See also  Auto-Update Custom Date field using Flow in Salesforce

How to Create Auto-Launched Flow In Salesforce

We will create the auto-launched flow in Salesforce using the above scenario and the following steps.

1. We need to send an email when the account is created. For this, we need two things: the Recipient’s Email address and the Email Body.

The Recipient’s email we will be getting in the Account record, but we need to create an Email Body.

To create the email body, we need a screen flow for that. I have already created a Screen Flow for creating an account. So, I’m going to edit the screen flow and click on the Manager tab, where we can get the New Resource option. Click on the new resource option to create an Email Template.

Create Auto Launched Flow in Salesforce

2. Now, you have to create an email body. For that, in the Resource Type field, you have to select the Text Template option. Then, this API Name will be used in the sub-flow.

The Description is optional; we can introduce our template shortly. Then, in the Body, we can enter the message that we want to share in the email.

After that, click the Done button to Save your email template resource.

Now, we need to pass these two things—the Email and the Email Body, which we have created now as an EmailTemplate—to the Sub-Flow.

Create Auto Launched Flow in Salesforce Lightning

3. Now, using the following steps, we will create an Auto-Launched flow as a Sub-Flow.

Log in to Salesforce Org. -> Click on the Setup. -> Home Tab. -> In Quick Find Box, Search for Flows. You will see an option under Process Automation. -> Click on Flows.

Auto Launched Flow in Salesforce Lightning

4. Click on the New Flow button to create a new flow.

Auto Launched Flow in Salesforce

5. As per the above scenario, we want to create an email action, which we will use in a different flow. For that, we will select the Auto-Launched Flow option, and this flow will be used as a sub-flow.

Then click on the Create button to proceed.

Auto Launched Flow in Salesforce Classic

6. Now, in this flow, we need to create two variables to take the value from the other flow. In our case, we will take value from screen flow. So, we will be creating the following two resources:

  • Email:
  • Email Body:
See also  How to Send Custom Notification using Flow in Salesforce

To create the resources click on the Manager tab, where we can get the New Resource option. Click on the new resource option. In the Resource Type field, you have to select the Variable option. Then, enter the API Name as per your requirement.

The Description is optional; we can introduce our variable shortly. The Email is in the text format, so here we have to select Data Type as Text. The Availability Outside The Flow must check Available for input. If you will not be checking it, it will not be available for input in the screen flow whenever you choose it.

Then click on the Done button.

Create the same variable for the Email Body; the only change is that you have to change the API name and the rest of the things the same.

Create a Auto Launched Flow in Salesforce

7. Now, we are going to add an Email Action to the auto-launched flow. To do that, click on the Add Element icon. Then select the Action option under the Interaction category.

How to Create a Auto Launched Flow in Salesforce

8. Then, under the Category, we need to select the Email option, select the Send Email option, and enter the necessary information.

How to Create Auto Launched Flow in Salesforce Classic

9. We also need to set input values for the selected actions. For the Body here, we already have created the EmailBody variable. Select that variable. Then, we created an Email variable for the Recipient Address List and selected it.

Then click on the Done button.

What is Auto Launched Flow in Salesforce

10. As you click on the Save button then, you need to enter the following information.

  • Flow Label: Here, I have entered Auto-Launched flow for sending email.
  • Flow API Name: It will automatically populate as we click the text box. This API name is used to give reference in the Apex or another flow.
  • Description: Description is optional; we can introduce our flow shortly.

Then click on the Save button.

Create Auto Launched Flow in Salesforce Classic

11. Now, we will add the Sub-Flow to the Screen Flow. To do so, click the Add Element icon and select the Sub-Flow under the Interaction option.

What is Auto Launched Flow in Salesforce Lightning

12. In the Referenced Flow option, select the Auto-Launched flow you created in the above steps. Then, enter the necessary information. The description is an optional field. You can leave it blank.

What is Auto Launched Flow in Salesforce Classic

13. Then, in the Set Input Values Fields, we will select the email and email template we created first in the screen flow, which will refer to the variable created in the auto-launched flow.

See also  How to Add Validation to Screen Flow in Salesforce

Then click on the Done button.

What is Auto Launched Flow in Salesforce example

14. Here, you can see that we have added the Sub-Flow after the Create Account Records element because we want to execute this Sub-Flow only after account creation.

This Screen Flow will invoke the Sub-Flow, which is the Auto-Launched flow. Then click on the Save button. Before Activating the flow, always Debug the flow. It’s good practice for flow creation. After that, click on the Activate button.

How to Create a Auto Launched Flow in Salesforce example

15. Now, we will create the record with the screen flow and will check whether, after creating the record, it is sending an email or not.

Auto Launched flow in Salesforce Lightning example

16. Here, you can see I have got an email after creating the account.

Auto Launched flow in Salesforce example

This is how we can create the auto-launched flow and use it as a sub-flow in another flow in Salesforce.

Conclusion

I hope you have an idea about creating an auto-launched flow in Salesforce. In this article, we have seen what an auto-launched flow is and when it can be used. Additionally, we have also seen how to create an auto-launched flow in Salesforce with the scenario.

We have also seen how we can use the auto-launched flow as a sub-flow in another flow, in that we have seen creating variables and using them in the sub-flow, and we have seen how to invoke an auto-launched flow in another flow.

You may like to read: