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 are 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.

retrieve recrod type in flow

Now you are understood 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.
Flow variable

Step 3:- Adding the Get Record element to fetch record Type id for a specific object and storing 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 varibale i.e {!varRecordTypeId}.
  8. Click Done.
getrecord

Step: 4 Adding the Decision element for a null check.

From the above get record, we will get the id of 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 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.
decision check

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 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 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.
screen element

Step: 6 Adding create record element to create a record.

In this element what value we entered in screen element those, we are mapping to the account field and assigning record Type Id and creating a record.

  1. Click the (+) icon and choose to create 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.
create record

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 how it looks like.

finalflow

Once you are done with this let’s perform the below step to save the flow.

  1. Click Save.
  2. Enter 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.

Sharing Is Caring:

Leave a Comment