Create and Use recordId Variable in Salesforce Flow : Bijay Kumar
by: Bijay Kumar
blow post content copied from SalesForce FAQs
click here to view original post
### Summary of Salesforce Flow and the 'recordId' Variable When working with Salesforce Flow, accessing the ID of the currently opened record is crucial. This record ID allows the flow to perform specific operations on that record, such as displaying its ID, counting related records, or creating new records associated with it. To utilize the record ID in Salesforce Flow, you must create a variable called `recordId`. This variable is a type of resource that enables the flow to identify which record it is interacting with. You will pass this variable through the Lightning Record Page. ### Key Details: - **Purpose of `recordId`:** It allows the flow to determine the specific record being worked on, enabling various operations. - **Creation of `recordId`:** You create this variable in Flow Builder by selecting the Variable resource type, naming it `recordId`, and setting it as available for input. - **Usage Scenarios:** - Displaying the opened record's ID and important fields. - Creating related child records from a parent record page. - Retrieving record IDs from Apex classes. ### Example Scenarios: 1. **Creating Related Records:** - For instance, in a real estate context, agents can create a Site Visit Request directly from a Customer record page. The flow uses the `recordId` to link the request to the correct customer. 2. **Using Apex to Trigger Flows:** - In a healthcare scenario, an appointment confirmation email can be sent automatically when a new Appointment record is created. The flow receives the `recordId` from an Apex trigger to identify which record to work with. ### Steps to Create and Use `recordId` in Salesforce Flow: 1. **Creating the Variable:** - Navigate to Flow Builder, create a new Variable, name it `recordId`, set the data type to Text, and check the option for availability outside the flow. 2. **Using the Variable:** - Add a Screen element to gather user input and a Create Record element to create a new record, using the `recordId` where necessary. 3. **Testing and Activation:** - Always debug the flow before activation to ensure it functions correctly. ### Conclusion Understanding how to create and utilize the `recordId` variable in Salesforce Flow is essential for performing operations on specific records. This capability enhances the efficiency of workflows in various business contexts. ### Additional Information For further reading, you might explore topics like: - Wait Element in Salesforce Flow - Using Formulas in Salesforce Flow - Checking if Get Records Is Empty in Salesforce Flow ### SEO Hashtags #Salesforce #SalesforceFlow #recordId #SalesforceTutorial #CRM #Automation #Apex #Lightning #SalesforceDevelopment #FlowBuilder #SalesforceBestPractices
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 Formula Resource, click the Toolbox icon and then click the New Resource button.

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:
- API Name: Now we need to give the API Name. Ensure that the variable name must be exactly recordId to assign the record ID from the object. If you name it RecordId, recordid, or anything else, it will not work.
- Data Type: The record ID is always a text string, so set the data type to Text.
- Availability Outside the Flow: We must check the Available for input option. That means we will pass the input ID from the Lightning record page or Apex to the flow.
Then click the Done button.

After creating the Variable resource, you will see that it is listed under the Manager tab, with the API Name that you provided.

In this way, we can create the recordId variable resource in Salesforce Flow.
Use a ‘recordId’ Variable Resource Type in Salesforce Flow
Now I will explain how we can use the recordId variable to pass the record’s ID to Salesforce Flow.
Example 1: Pass recordId from Lightning Record Page to Flow
For a real estate company, agents track customer records and site visit requests in Salesforce. When a customer wants to visit a property, the agent needs to record which site the customer wants to see.
Instead of going to the Site Visit Request object separately, agents want an easier way to log the request.
They requested the creation of a Screen Flow on the Customer record page, enabling them to directly create a Site Visit Request from the customer’s record. This will save time and automatically link the request to the correct customer.
Now, we will create the screen flow to add components that will take input from the user for the Site Visit Request object.
To create the flow, navigate to Setup -> in Quick Find search for Flow -> New Flow -> Start From Scratch -> Screen Flow -> Next.
Next, create the Variable resource with the name recordId.
Next, add a Screen element to take the input from users. In this case, we are providing the details of the site visit request. To do that, click the Component tab, and add fields for which you want fill values.

Next, we need to create a record for the site visit request using the details the user provides in the screen component.
For that, add a Create Record element. Provide Label and API Name. Next, select the Object for which you want to create a record.
After that, in the fields, you will see selected object fields, and you need to assign a value for them.
Then, set the values for the selected object from the screen component and for the Client Name field, which is a lookup field on the Site Visit Request object. We need to provide the recordId variable that we created.

After that, this is an optional screen for displaying the success text after record creation.

Now we are ready to save the flow. To do this, click the Save button, provide the flow Label, and the API Name will be automatically populated.
After that, always debug the flow before activating it to ensure that the working flow is correct and that there are no runtime errors. Then activate the flow.

After that, navigate to the Clients object record from where you want to create a site visit request record for the client.
Click the Gear icon -> Edit Page.

After that, in the Component tab, search for the Flows. Drag and drop it onto the record page where you want it.
After that, on the right side, you will see the Flow option; there, you need to select the screen flow that you created. Also, you need to check the checkbox to pass the record ID into this variable.
That means whenever we open any client record, that record ID will get passed to the flow, and the flow will create the record for that ID.
After that, save the page.

Now, again navigate to the client object record, and this time you will see the fields you added in the screen component to create the site visit request record. Fill in the details and click the save button.

If you have added the screen to display text, you will see the message if a record is created.

Additionally, you can verify by navigating to the Site Visit Request object record that was created for the client from which this record was created.

In this way, we can create the related record by passing the recordId variable from the Lightning record page to Salesforce Flow.
Example 2: Pass recordId from Apex Code to Flow
Whenever we create a new Appointment record from Apex, we want to automatically send a confirmation email to the patient so they are aware that their appointment is booked.
However, the flow needs to know which Appointment record to work on. For this, we will pass the Appointment’s record ID into the flow from Apex code.
To create the flow, go to Setup -> in Quick Find search for ‘Flows‘ -> click the New Flow button -> select Start From Scratch -> Autolaunch Flow(No Trigger) -> Create.
Next, create the Variable resource with the name recordId.
Next, we need to retrieve the patient records stored in the Patient__c object. For that, we need to add the Get Records element and enter a Label and API Name.
Then, to filter the patient records, add a condition. Here, I set the following two conditions to filter the records.
- Record ID (patient) equal to ‘recordId’ (a created variable).
- Appointment Status = Confirmed.
Now, the ‘recordId‘ variable will be passed into the Apex code. So that flow will know which record is being created or updated.

After obtaining the record, we will send an email to the patient whose appointment status is confirmed.
After that, we want to send an email once the wait is over. For that, add the Send Email action.
Here you need to select the field values to send an email, such as sender email, subject, body, recipient address, etc.
In the body, we inform the patients that their appointment has been confirmed.

Now we are ready to save the flow. For that, click the Save button, provide the flow Label, and the API Name will be automatically populated.
After that, always debug the flow before activating it to ensure that the working flow is correct and that there are no runtime errors. Then activate the flow.

After activating the flow, navigate to the flow details and copy the Flow API Name that you provided while saving the flow.
This API name needs to be passed in Apex code to call the flow.

Here, I created a Trigger to automate the process of sending an email when a new patient record is created with the appointment status as confirmed.
Here, we pass the recordId variable so that the flow knows which record to send an email to.
trigger AppointmentTrigger on Patient__c (after insert) {
for(Patient__c p : Trigger.New) {
Map<String, Object> params = new Map<String, Object>();
params.put('recordId', p.Id);
Flow.Interview.Call_Flow_From_Apex flowInstance =
new Flow.Interview.Call_Flow_From_Apex(params);
flowInstance.start();
}
}
After creating the Apex trigger, go to the patient object and create the record with appointment status as confirmed, and save the record.

You will see the patient’s email that you provided. The flow sent the email according to the body we provided in the flow.

In this way, we can pass the record ID from Apex code to Salesforce flow by using the recordId variable resource type in Salesforce.
Conclusion
I hope you have got an idea about the recordId Variable in Salesforce Flow in detail. In that, we learned 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.
You may like to read:
- Wait Element in Salesforce Flow
- Use Formulas in Salesforce Flow
- Check if Get Records Is Empty in Salesforce Flow
The post Create and Use recordId Variable in Salesforce Flow appeared first on SalesForce FAQs.
June 27, 2025 at 03:41PM
Click here for more details...
=============================
The original post is available in SalesForce FAQs by Bijay Kumar
this post has been published as it is through automation. Automation script brings all the top bloggers post under a single umbrella.
The purpose of this blog, Follow the top Salesforce bloggers and collect all blogs in a single place through automation.
============================

Post a Comment