In this Salesforce tutorial, we will learn to Pass a Record ID into Salesforce Flow and for that, we will create a Salesforce Flow with a record ID variable and then pass that flow to the Salesforce records displaying the Record ID. We can pass a Record ID into flow in Salesforce Lightning only because in classic there is no feature to create a flow.
Record ID into Salesforce Flow
In Salesforce records, each record has a unique record ID and that record ID is visible in the URL when we open the record detail page. We can also access and display this record ID on the record detail page with the help of a salesforce flow.
In Salesforce flow a Record ID is a reference to a specific record in the database. This Record ID can be used to update the details of a record, like a Contact, an Account, or an Opportunity.
While working for an organization that uses Salesforce as a CRM tool to track and manage their clients’ data, I was asked to pass Record ID into Salesforce flow. With the help record Id in flow, we can get the account details easily and we do not have to perform a Get Record operation that will make flow perform faster.
In the below steps, I will explain to you the method of Passing a Record ID into Salesforce flow with the help of an example below.
Pass a Record ID into Salesforce Flow from the Screen component in Lightning
To Pass a Record ID into Salesforce flow in Lightning we are going to see this process in two parts that are:
- Creating a Flow with Record ID in Salesforce Lightning.
- Adding the Record ID flow to the Record page.
Create a Flow with Record ID in Salesforce Lightning
To create a Record ID into Salesforce Flow in Lightning, first log in to your Salesforce account and follow the steps below.
Step-1: On the Setup page of Salesforce Lightning, go to the Quick Find box and search for flow, and from the option in the dropdown under the heading Process Automation select the option Flows.
Step-2: In the Flows setup menu click on the button New flow to create a flow.
Step-3: In this step, we have to select the flow type to create the new flow. To Pass a Record ID into Salesforce Flow select the Screen Flow option and then click on the Create button.
Step-4: The flow is created and now we are going to create a resource to store the record ID for that click on the toggle icon on the left side, and it will open a Toolbox. In the Toolbox click on the button New Resource.
Step-5: In this step, we will use the required details in the fields to create a new resource for the flow.
- In the field, Resource Type select the value as Variable because it’s going to be different depending on what record you will trigger this automation from.
- In the API Name field use lowercase with ID for example I’ve entered the API name as accountId and it can be entered as recordId or OpportunityId as well.
- In the Data Type field select Text as a data type and make sure to activate the checkbox available for input.
- After making the changes above, click on the Done button.
Step-6: To add an element, hover over the circle below Screen Flow and click on the “+” sign as shown in the picture below.
Step-7: In this step, select the option Screen under the heading Interaction.
Step-8: As we click on Screen a new window will appear, and here we will define the screen properties to create a new screen for the flow.
In the Screen Properties on the right-hand side enter the Label for the screen flow. For example, I have entered the Label as Account Id in Flow. On entering the Label the API Name field will be auto-filled.
On the left-hand side in the Components section, select the component Display Text drag it to the region of Flow Label, and drop it there.
Step-9: In this step, we have to enter fields for the Display text component we have added to the screen flow.
- In the API Name field enter the appropriate API name. For example, I have entered the API name as accountIdDisplay Text.
- In the text area of the Display Text, add text according to the record name. For example have added text as “Your accountId is:“.
- To add a resource to the flow click on the search bar Insert a resource.
Step-10: As we click on Insert a Resource, it will open a dropdown and there select the created variable accountId under the heading Variables.
After selecting the variable, click on the Finish button in Flow Label and then click on the Done button to apply the settings.
Step-11: Now the flow is created as we can see in the picture below, click on the Save button.
Step-12: As we click on the Save button, a pop-up window will appear, here enter the Flow Label and Flow API name. For example, I have entered the Flow label as Account detail flow and the Flow API name as Account_detail_flow. Last click on the Save button.
Step-13: To activate the saved flow click on the Activate button as shown in the picture below.
As we click on the Activate button the flow will be activated and it will show a message on the screen as “Your flow was activated“.
With this, we have created a Flow with the passed Record ID in Salesforce Lightning.
The further tutorial will teach us how to pass or add this created record ID flow in a Salesforce Record Page.
Adding the Record ID flow to the Record page
There are two ways by which we will display the Record ID on the record page.
- Adding the Record ID flow to the Record page from the Screen Flow.
- Adding the Record ID flow to the Record page from Button Actions.
Adding the Record ID flow to the Record page from the Screen flow
To add the Record ID flow to the Record page in Salesforce Lightning, go to the Setup page of Salesforce Lightning and follow the steps below.
Step-1: On the Setup page of Salesforce Lightning, click on the App launcher (9 dots), and search for the Sales, from the options in the dropdown select Sales.
Step-2: In the Sales application, select the Accounts tab to access account records.
Step-3: In the Accounts, select any one account record. For example, I have selected the account record Express Logistics and Transport.
Step-4: On the record page, click on the settings icon on the upper right side of the screen, and from the dropdown select Edit Page.
Step-5: As we click on the Edit page, the record page will open in the lighting app builder. Now, we will add a flow component to the record page, and for that select the Flow component from the standard components on the left-hand side and drag it to the template region of the record page.
Step-6: After adding the flow component, go to the right sidebar, and in the Flow field, select the flow that you have created. For example, I have selected the created flow Account detail flow
As we click on the Save button the flow with the record ID will be added to the Lightning Record page.
Step-7: On the Accounts Page of Salesforce Lightning open any account record to view record ID. In this example, I have selected the account Edge Communications.
When we open the Account record, it will display the Record ID in the component where we added the flow.
Now we have successfully the flow on the Record page displaying the ID of the Record.
Adding the Record ID flow to the Record page from Button Actions
To Pass a Record ID into Salesforce Flow from buttons, go to the Setup page of Salesforce Lightning and follow the steps below.
Step-1: On the Setup page of Salesforce Lightning, click on the Object Manager from the tabs.
Step-2: In the Object Manager select an object like Account, Contact, or Opportunity to pass a record ID. In this example, I have selected the object Account.
Step-3: In the Account object, go to the Details section on the left side and select Buttons, Links, and Actions.
Step-4: In this step, click on the button New Action that is on the upper right side of the window to start a flow.
Step-5: In this step, we have to enter details for the Action Information.
- In the Action Type field click on the dropdown arrow and from the options in the dropdown.
- In the Flow field, click on the dropdown arrow and select the flow you have created above. For example, I have selected the created flow Account detail flow.
- In the Label field enter the label for the button. In this example, I have entered the Label as Account Record ID. As we enter the Label it will auto-fill the Name field.
Step-6: Now the button action is created and we will go to the page layout to add this action over there. Now for that, click on the Account object in this window.
Step-7: In the Account object setup, click on the Page layouts under the heading Details.
Step-8: In the Page Layouts window, there will be a list of account page layouts. Here, select the page layout named Account Layout.
Step-9: In the account’s page layout click on the Mobile & Lightning Actions on the upper left-hand side and as we click on it we can see a list of actions on the right side of that.
From the list of actions select the created action Account Record ID and drag it to the section Salesforce Mobile and Lightning Experience Actions. After making these changes click on the Save button.
Step-10: Now go to the Accounts tab of Salesforce Lightning and select an account record. For example, I have selected the account Burlington Textiles Corp of America.
Step-11: As we open the account record, we can see the button action Account Record Id is visible on the upper right side of the screen. To see the record Id of the record, click on the button Account Record Id.
As we click on the button Account Record Id, a pop-up screen will appear displaying the record ID of the selected account as shown in the picture below.
In this way with the help of the button action, we displayed the record ID that was passed in a Salesforce flow.
In this Salesforce tutorial, we have learned about Passing a Record ID into a Salesforce Flow. During this, we created a Salesforce flow with a recordId variable and later we displayed that recordId flow on the record page using two possible methods in which first we added the recordId flow from Screen flow, and in the second method we displayed the recordId with the help of button actions.
You may like to read:
- How to Add Calendar to the Record Page in Salesforce Lightning
- How to add a Pop-up message in the Salesforce Record Page
I am Bijay Kumar, the founder of SalesforceFAQs.com. Having over 10 years of experience working in salesforce technologies for clients across the world (Canada, Australia, United States, United Kingdom, New Zealand, etc.). I am a certified salesforce administrator and expert with experience in developing salesforce applications and projects. My goal is to make it easy for people to learn and use salesforce technologies by providing simple and easy-to-understand solutions. Check out the complete profile on About us.