How to Query for a Record Type in Salesforce Flow

newsletter Oct 05, 2024

Best Practice: Query for your record types in Salesforce Flows (and Apex)

What You'll Need:

  • Object Name
  • Record Type Name

How To Do It:

  • Use a Get Records element in your flow on the "Record Type" object.
  • Filter on the SobjectType field
  • Filter on the Name field 

In the screenshot above you can see we're querying the "Record Type" object.

We set the SobjectType = Contact, and the Name = Client.

So this query searches Record Types on the Contact object where the name of the record type is "Client".

Then we can use the result of that query to set the RecordTypeId field in a Create or Update record element:

When It Matters:

  • When creating new record types in lower sandbox environments the RecordTypeId will change as you promote it to higher sandbox environments (and production). This approach helps avoid problems during deployments
  • If a Record Type is used in multiple places in a flow, and then you need to change it later, you'll save yourself time by only having to update one single query rather than reworking multiple create / update elements
  • Knowing this approach is useful in technical interviews when asked about architecture best practices

And that's a wrap!

SalesforceĀ Saturdays

Join the Salesforce Saturday newsletter. Every Saturday, you'll get 1 actionable tip on Salesforce technology or career growthĀ related to the Salesforce Industry.

We hate SPAM. We will never sell your information, for any reason.