In Salesforce, RecordTypes allow us to group records of the same type for an object. It will enable the customization of page layouts, fields, required fields, and picklist values for different user profiles, as well as restrict field access for layouts and the creation of records.
For example, you can create record types to ensure that a team only sees customer accounts, not partner ones.
Each RecordType in Salesforce is represented by the RecordType object and is associated with standard or custom objects, such as accounts, opportunities, or custom objects.
SOQL Queries to Get RecordType
In the examples below, we will discuss scenarios where we execute SOQL to retrieve the record type names, IDs, and developer names of different objects.
Get Recordtype Name and ID Using SOQL Query
In the SOQL query below, we will retrieve the name and ID of the record type from the account object.
SOQL query:
SELECT Id, Name FROM RecordType WHERE SobjectType = 'Account'Output:

Get Specific RecordType Details in SOQL query
In the SOQL query below, we retrieve active record types for the Case object, including their name, ID, and developer name, from the active record types.
SOQL query:
SELECT Id, Name, DeveloperName FROM RecordType WHERE SobjectType = 'Case' AND IsActive = trueOutput:

Get Salesforce Object Records Assigned to a Record Type using SOQL
Using the SOQL query, we can also retrieve the records related to a specific record type in the Sobject.
Using the SOQL query below, we have retrieved Case records assigned to a specific record type by filtering the records by DeveloperName.
SOQL query:
SELECT id, Priority FROM Case WHERE RecordTypeId IN (SELECT Id FROM RecordType WHERE DeveloperName = 'Sales_Support')
After executing the above query, we retrieved the case records assigned to the record type with the developer name Sales_Support.
Get Records from Record Type Name in Salesforce SOQL
Instead of retrieving records from record type ID or developer name, we can also fetch the record details of a specific record type by its name using RecordType.Name in the SOQL query.
SOQL query:
SELECT Id, Subject FROM Case WHERE RecordType.Name = 'Product'Output:

In the above SOQL query, we have retrieved the case record details, such as subject and ID, where the record type name is “Product.”
Retrieve Record Types of all Objects in Salesforce SOQL
When you need to retrieve all the record types in your Salesforce org, you can execute the SOQL query below to fetch the details of the record types.
SOQL query:
SELECT Id, SobjectType, Name, DeveloperName FROM RecordTypeOutput:

As we can see in the output, we have received all record types with their details in the Salesforce org.
Count the number of records assigned to each record type in an object using SOQL.
For example, if you have an object with many record types and want to track the number of records assigned to each record type, then you can execute the SOQL query below.
SOQL query:
SELECT RecordType.Name, COUNT(Id)
FROM Case
GROUP BY RecordType.NameOutput:

In the above query, we have counted the number of records assigned to different record types of the Case object. In the output, we can see the count of records assigned to each record type.
This way, we can query sObject record type details in Salesforce SOQL queries by following the above methods.
Conclusion
In this Salesforce tutorial, we learned how to execute SOQL queries to retrieve and analyze record types and their associated records across various objects, such as Accounts and Cases. These queries allow for filtering by RecordType ID, DeveloperName, or Name, providing ease in retrieving the data.
By following the above methods in relation to specific scenarios, you can execute SOQL queries efficiently and retrieve information related to the record types.
You may also like to read.
- Polymorphic Relationships in Salesforce SOQL
- Salesforce SOQL Logical Operators
- Selective SOQL Queries in Salesforce
- Dynamic Queries in Salesforce SOQL
- OFFSET Clause in SOQL
I am Bijay Kumar, the founder of SalesforceFAQs.com. Having over 10 years of experience working in salesforce technologies for clients across the world (Canada, Australia, United States, United Kingdom, New Zealand, etc.). I am a certified salesforce administrator and expert with experience in developing salesforce applications and projects. My goal is to make it easy for people to learn and use salesforce technologies by providing simple and easy-to-understand solutions. Check out the complete profile on About us.