Hello Everyone, In this post let’s understand and create a flow to retrieve record Type id’s using flow rather than directly hardcoding record Type id’s. If you have not followed our previous blog post related to flows, Aura feel free to check those out.
Table of Contents
Use Case Example
In my account object, I have two record Types i.e, Partner account and Customer account. If the account is created from ScreenFlow then the record Type should be a Partner account.
How to fetch record Type ID in flow salesforce
We have understood our use case now let’s achieve this with the flow. Before that let’s check the use case diagram below.
Now you understand how we are achieving this scenario using flows. so let’s create a flow to retrieve record type ID using flow.
Step 1: – Define flow properties
- Click Setup.
- In quick find box search flows.
- Select the flow and click on new flow.
- Select Screen Flow and click on Create.
Step 2:- Text Variable to store the RecordType Id.
- Under Manager left side, click on New Resource to create a text variable.
- Input the following information.
- Resource Type: Variable.
- API Name : varRecordTypeId.
- Data Type: Text.
- Availability Outside the Flow: Choose Available for input.
- Click Done.
Step 3:- Adding the Get Record element to fetch the record type ID for a specific object and store id in the text variable.
This get record element will find a specific record Type for a specified SObject and we are storing the id in the text variable.
- Click on (+) and choose the get record element.
- Enter the Label and the API Name will auto-populate.
- Select the object as Record Type.
- Select All Conditions Are Met (AND).
- Set filter conditions as below.
- Row 1 :
- Field: SobjectType.
- Operator: Equals.
- Value: Account.
- Row 2 :
- Field: DeveloperName.
- Operator: Equals.
- Value: Partner_Account.
- Row 1 :
- How Many Records to Store.
- Select only the first record.
- How to Store Record Data.
- Choose the option to Choose fields and assign variables (advanced).
- Where to Store Field Values.
- Choose the option In separate variables.
- Select Variables to Store Record Type Fields.
- Field: Id.
- Variable: Choose the above-created variable i.e {!varRecordTypeId}.
- Where to Store Field Values.
- Choose the option to Choose fields and assign variables (advanced).
- Click Done.
Step: 4 Adding the Decision element for a null check.
From the above get record, we will get the ID of the record Type. Suppose the get record element returns null, we are verifying the get record collection in the decision element.
- Click on the (+) icon and choose the decision element.
- Add Label and automatically API Name will populate.
- OUTCOME DETAILS.
- Add a label and Outcome API Name.
- Condition Requirements to Execute Outcome.
- Select All Conditions Are Met (AND).
- Resource : getRecordTypeofAccount.
- Operator: Is Null.
- Value: False.
- Click Done.
Read the best salesforce Books: Click Here.
Step: 5 Adding screen element to create an account.
In this element, we are accepting some fields of account and we are creating an account.
- Click the (+) icon where your decision check will become true.
- Add screen element Screen Properties(Right-hand side) add label and API Name automatically will populate.
- Drag Text Input (Left-hand side) to the screen and add a label and the API Name will populate automatically.
- For the text input make Require check box true.
- Drag Phone Input (Left-hand side) to the screen and add a label and the API Name will populate automatically.
- Make footer adjustments to the screen as per your wish.
- Click Done.
- For the Default outcome of the decision click(+) and choose End.
Step: 6 Adding create record element to create a record.
In this element what value we entered in the screen element, we are mapping to the account field and assigning record Type Id, and creating a record.
- Click the (+) icon and choose to create a record element.
- Add Label and API Name will populate automatically.
- How Many Records to Create?
- One.
- How to Set the Record Fields.
- Choose the option Use separate resources and literal values.
- Create a Record of This Object.
- Object: Account.
- Set Field Values for the Account.
- Name: {!Account_Name_0}.
- Phone: {!Phone_0.value}.
- RecordTypeId : {!varRecordTypeId}.
- Click Done.
Note: – Don’t confuse with zero(0) at the end. Those will automatically append to the API name. Assigned values to the name, and phone are from the screen element and for RecordTypeId from a variable (Step 3).
Congratulations now we are done with our flow let’s see what it looks like.
Once you are done with this let’s perform the below step to save the flow.
- Click Save.
- Enter the Flow Label the API Name will auto-populate.
- Click Show Advanced.
- API Version for Running the Flow: 54
- Interview Label: RecordType Account Flow {!$Flow.CurrentDateTime}.
- Click Save.
Output: –
I have added this ScreenFlow on the home page and let’s check the result.
Also Read
- Read the best salesforce Books: Click Here.
- HTTP Callout in Salesforce Flow Without Code [GET & POST]
- How to Invoke a Flow from a Lightning Web Component
- How to update child records using salesforce flow
- How to Assign records to Queue using Salesforce Flow?
- How to create a Data Table in Salesforce Flow : Complete Guide.
- How to retrieve record Type Id in flow
- How to navigate record detail page in flow
- How to send email using flow in salesforce
- How to Display Icon In Lightning Datatable
- How to Create Record in lightning Component
- How to Delete Multiple Records Using Checkbox In Lightning Component.
Thanks for detail info. it was very much useful.
Thanks, Sree.
I followed along for my record triggered flow, but keep getting this error message:
This error occurred when the flow tried to create records: INVALID_CROSS_REFERENCE_KEY: Record Type ID: this ID value isn’t valid for the user: . You can look up ExceptionCode values in the SOAP API Developer Guide.
Any advice you can provide to correct my issue??
thankyou!
Hi Eileen,
Pls check if the user has access to that record type you are accessing. if possible could you please share a screenshot of your flow? Feel free to email as well.