I am looking for a SOQL query to get the list of record type Id for a given sObject Name

4 Answers 4


By querying the recordType object and filtering by the sObjectType

select Id,Name from RecordType where sObjectType='Account'
  • It takes a minute for you to post a question and 2 for finding the answer. In that case I suggest you should do more research. Still good to see that you are able to answer your own question :)
    – Raul
    Commented May 5, 2017 at 7:58
  • 3
    @RahulSharma I'm just sharing some knowledge here, I am following this stack recommendation => stackoverflow.com/help/self-answer ;)
    – benahm
    Commented May 5, 2017 at 8:18
  • Ah thanks for the clarification, it was not clear from your question and answer.
    – Raul
    Commented May 5, 2017 at 8:26

While this can be accomplished with SOQL, SOQL queries are a precious resource and we have but a scant few in each transaction.

There is a way to get this information without using a single query by using SObjectDescribe.

// The general expression to use is 
//   Schema.SObjectType.<your SObject's API name here>.getRecordTypeInfosByName()
// I'll be using Account in this example
Map<String, Schema.RecordTypeInfo> recordTypes = Schema.SObjectType.Account.getRecordTypeInfosByName();

Id standardRecTypeId = recordTypes.get('Parent').getRecordTypeId();
Id customRecTypeId = recordTypes.get('My Record Type Display Name').getRecordTypeId();

Schema.RecordTypeInfo has a few other methods, which can be found by looking through the documentation on this class, but getRecordTypeId() is basically the only method from this class that I ever call.

+edit 2023:

getDeveloperName() was added as a method sometime around Summer '18 (API v43.0)

  • 3
    But then you can't get unique identifiers like DeveloperName, right?
    – Adrian Larson
    Commented May 5, 2017 at 13:06
  • @AdrianLarson indeed. This method doesn't give access to BusinessProcessId, DeveloperName, IsPersonType, Description, or Namespace_Prefix. You'd need to query if you happened to need any of those fields, but in that case it's probably better to use something like the org cache to avoid querying over and over.
    – Derek F
    Commented May 5, 2017 at 13:20
  • @AdrianLarson I just realised, you can get the DeveloperName. I just browse through the documentation link provided in this answer. There's a method "getDeveloperName()", which returns the DeveloperName of the recordType. As this answer is posted almost 6 years ago, I am not sure if this method was available back then or not, just sharing what I found recently.
    – prem22
    Commented Nov 16, 2023 at 3:23
  • Yeah they've changed the API a lot since 2017.
    – Adrian Larson
    Commented Nov 16, 2023 at 20:49

When working in a new org, I often write a caching mechanism that gets them all in one go. It's not a ton of query rows or processing time and saves queries in the long run:

public with sharing class RecordTypeCache
    public static Map<String, RecordType> get(SObjectType key)
        return cache.containsKey(key) ? cache.get(key) : new Map<String, RecordType>();
    public static RecordType get(SObjectType key, String developerName)
        return get(key).get(developerName);

    static Map<SObjectType, Map<String, RecordType>> cache
            if (cache == null)
                cache = new Map<SObjectType, Map<String, RecordType>>();
                Map<String, SObjectType> objects = Schema.getGlobalDescribe();
                for (RecordType recordType : [SELECT DeveloperName, SObjectType FROM RecordType])
                    SObjectType schemaType = objects.get(recordType.SObjectType);
                    if (!cache.containsKey(schemaType))
                        cache.put(schemaType, new Map<String, RecordType>());
                    cache.get(schemaType).put(recordType.DeveloperName, recordType);
            return cache;
        private set;

So if you wanted to get the List<RecordType> for a specific SObjectType, you would just do:

List<RecordType> myObjectRecordTypes = RecordTypeCache.get(MyObject__c.sObjectType).values();

@benahm As per your comment "I'm just sharing some knowledge here, I am following this stack recommendation => [stackoverflow.com/help/self-answer] " to @RahulSharma.

Yes, that's a good thing but the kind of question which you've posted is very basic question. If you find something new which has not been discovered earlier then you're free to post it.

I just went to Ask Question section and I tried to ask a question similar to your question and look what I found:

enter image description here

And though you've answered in SOQL, but I guess it's better to use in Apex so that you can build some logic around it.

List<RecordType> lstAccountRecordTypes = [SELECT Id, Name FROM RecordType WHERE sObjectType='Account'];
System.debug('Record Types:'+lstAccountRecordTypes.size());
  • 4
    I agree with your comment: * the kind of question which you've posted is very basic*. The level of research displayed in the question itself is quite poor, even if it was posted as a Q&A.
    – Adrian Larson
    Commented May 5, 2017 at 12:50
  • In my case I wasn't looking for how to get the record type Id in Apex, I was just looking for the fastest way to get it, cause I needed to use it in a process builder for testing purpose...
    – benahm
    Commented May 5, 2017 at 19:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .