Create and Use recordId Variable in Salesforce Flow

While working on Salesforce Flow, we often need to access the ID of the currently opened record. This record ID helps us to run the flow on that specific record.

When we pass the record ID, the flow can determine which record we are working with, allowing us to perform operations such as displaying the ID of the opened record on screen, displaying related record counts, and creating associated records from the parent record, etc.

To pass the opened record ID to the Salesforce flow, we need to create a recordId variable in the flow, which is one of the types of resources. Then again, we need to pass that variable in the Lightning Record Page.

In this tutorial, I will explain the how to create and use recordId variable in Salesforce Flow in detail. In that, we will understand why we need to create a record ID variable, how to use it, and how to pass the ID of the opened record to the Salesforce flow.

What is the ‘recordId’ Variable in Salesforce Flow?

The recordId variable in Salesforce flow is a Variable Resource Type. Using that, we can access the ID of the opened record, and the flow will perform operations on that record.

Using the record ID, we can also access the ID from the apex classes. For that, we need to pass the created variable to the class where we access the records.

Let’s understand it by example: We have created a screen flow to create the account-related contact record. Then we deploy that flow on the account record page. Now, here is how the flow will know for which account it has to create related contacts?

For this, within the flow, we create the recordId variable and then pass it to the account record page, allowing the flow to pass the opened account record ID and create a contact record for the account.

Where can we use ‘recordId’ Variable Resource Type?

In Salesforce Flow, the recordId variable is usually used in screen flows that are launched from a Lightning Record Page.

I will explain for which operations we can use the recordId variable. Then we will understand how to create it and use it in the operations.

  • When we create the screen flow, we want to display the currently opened record’s ID and important fields with values.
  • When we want to create the related child record from the parent record page.
  • When we retrieve the record ID from the Apex class and pass it to the flow.

Create a ‘recordId’ Variable Resource Type in Salesforce Flow

Now, I will explain how to create the recordId resource in the Flow Builder.

To create a recordId Variable Resource, click the Toolbox icon and then click the New Resource button.

Resource Type in Salesforce Flows

As you click the Resource Type dropdown field, you will see various resources, such as Variable and Text Template. Here we need to select the Variable.

Now we need to provide the details for the following fields:

  • AP