How to retrieve record Type Id in flow

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.

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

  1. Click Setup.
  2. In quick find box search flows.
  3. Select the flow and click on new flow.
  4. Select Screen Flow and click on Create.

Step 2:- Text Variable to store the RecordType Id.

  1. Under Manager left side, click on New Resource to create a text variable.
  2. Input the following information.
    1. Resource Type: Variable.
    2. API Name : varRecordTypeId.
    3. Data Type: Text.
    4. Availability Outside the Flow: Choose Available for input.
  3. 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.

  1. Click on (+) and choose the get record element.
  2. Enter the Label and the API Name will auto-populate.
  3. Select the object as Record Type.
  4. Select All Conditions Are Met (AND).
  5. Set filter conditions as below.
    1. Row 1 :
      1. Field: SobjectType.
      2. Operator: Equals.
      3. Value: Account.
    2. Row 2 :
      1. Field: DeveloperName.
      2. Operator: Equals.
      3. Value: Partner_Account.
  6. How Many Records to Store.
    1. Select only the first record.
  7. How to Store Record Data.
    1. Choose the option to Choose fields and assign variables (advanced).
      1. Where to Store Field Values.
        1. Choose the option In separate variables.
      2. Select Variables to Store Record Type Fields.
        1. Field: Id.
        2. Variable: Choose the above-created variable i.e {!varRecordTypeId}.
  8. 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.

  1. Click on the (+) icon and choose the decision element.
  2. Add Label and automatically API Name will populate.
  3. OUTCOME DETAILS.
    1. Add a label and Outcome API Name.
    2. Condition Requirements to Execute Outcome.
    3. Select All Conditions Are Met (AND).
      1. Resource : getRecordTypeofAccount.
      2. Operator: Is Null.
      3. Value: False.
  4. 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.

  1. Click the (+) icon where your decision check will become true.
  2. Add screen element Screen Properties(Right-hand side) add label and API Name automatically will populate.
  3. Drag Text Input (Left-hand side) to the screen and add a label and the API Name will populate automatically.
    1. For the text input make Require check box true.
  4. Drag Phone Input (Left-hand side) to the screen and add a label and the API Name will populate automatically.
  5. Make footer adjustments to the screen as per your wish.
  6. Click Done.
  7. 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.

  1. Click the (+) icon and choose to create a record element.
  2. Add Label and API Name will populate automatically.
  3. How Many Records to Create?
    1. One.
  4. How to Set the Record Fields.
    1. Choose the option Use separate resources and literal values.
  5. Create a Record of This Object.
    1. Object: Account.
  6. Set Field Values for the Account.
    1. Name: {!Account_Name_0}.
    2. Phone: {!Phone_0.value}.
    3. RecordTypeId : {!varRecordTypeId}.
  7. 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.

  1. Click Save.
  2. Enter the Flow Label the API Name will auto-populate.
  3. Click Show Advanced.
  4. API Version for Running the Flow: 54
  5. Interview Label: RecordType Account Flow {!$Flow.CurrentDateTime}.
  6. Click Save.

Output: –

I have added this ScreenFlow on the home page and let’s check the result.

Also Read

  1. Read the best salesforce Books: Click Here.
  2. HTTP Callout in Salesforce Flow Without Code [GET & POST]
  3. How to Invoke a Flow from a Lightning Web Component
  4. How to update child records using salesforce flow
  5. How to Assign records to Queue using Salesforce Flow?
  6. How to create a Data Table in Salesforce Flow : Complete Guide.
  7. How to retrieve record Type Id in flow
  8. How to navigate record detail page in flow
  9. How to send email using flow in salesforce
  10. How to Display Icon In Lightning Datatable
  11. How to Create Record in lightning Component
  12. How to Delete Multiple Records Using Checkbox In Lightning Component.

9 thoughts on “How to retrieve record Type Id in flow”

      • 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!

        Reply

Leave a Comment