Apex Tip: How to get a RecordType Id by Name without SOQL

The usual way to get a recordTypeId in Apex is to make a query like this:

Instead of that try this line:

Just replace Account and ‘Person Account’ by your Object and Record Type Name
I’ve been notice that “Person Account” is the label description and not the developer name of the Record Type. Having said that if you work in a multi-lang org, You’ll need to make a Query.
The most efficient way to make that kind of query is to cache the result in a static variable. Like this:


Happy coding

7 thoughts on “Apex Tip: How to get a RecordType Id by Name without SOQL

      1. mahanandeesh

        hi martin,
        I am new to coding,so i have few doubts regarding above code.can you please explain.

        1.you have AccountHelper class and you are checking personRecordTypeId is null by class name ,why? and what is that class(AccountHelper) ,is it a like controller?

        2.I have a cutomobject position with record type (ITposition and non IT position ) and controller is insertinrecordtypecontroller
        I have a field( postionvalue) in IT postion record type and I want to insert field value with out using id and in a good approch. can you please help for this.


  1. MichealToutc

    I see your site needs some unique & fresh content. Writing manually is time consuming, but
    there is solution for this hard task. Just search for:
    Miftolo’s tools rewriter

  2. EsperanzaSmall

    I have checked your page and i have found some duplicate content,
    that’s why you don’t rank high in google, but there is a tool that can help you to create 100% unique articles, search for: Boorfe’s
    tips unlimited content


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">