6

I want to get Developer Name of record Type without using SOQL query. With the below code, I'm able to get the "Name", but I want the DeveloperName. Let me know.

string recordTypeName = Schema.SObjectType.Account.getRecordTypeInfosById().get(Account.RecordTypeId).getName();
4
  • Why do you need the Developer Name rather than the name? Why do you need to do this without a SOQL query? Commented May 27, 2015 at 7:11
  • That API (think you are missing a getDescribe in your example) unfortunately does not provide the developer name so querying is the simplest option. @AlexTennant Examples of where I've used the developer name are conditional rendering in Visualforce pages and conditional rendering in Angular templates. But introducing named variables that hold the record type ID could be done instead - just uglier.
    – Keith C
    Commented May 27, 2015 at 7:38
  • 1
    im forming a regEx, its better to have DeveloperName than Name because Name has spaces! Don't want to use SOQL because I do not want to add a query just for this Commented May 27, 2015 at 7:58
  • @KeithC I understand why you might want to know what the DeveloperName is, I was trying to understand this particular situation though in case there were viable alternatives. Commented May 27, 2015 at 8:54

3 Answers 3

8

it will be possible from Summer'18 https://releasenotes.docs.salesforce.com/en-us/summer18/release-notes/rn_apex_developer_name.htm

Get the Developer Name for Record Types More Easily

We added Apex methods to help you get the developer name for record types more easily. Previously, the developer name was accessible only via SOQL on the RecordType SObject, and not via describe information.

Where: This change applies to Lightning Experience and Salesforce Classic in Enterprise, Performance, Unlimited, and Developer editions.

You can use the following methods to get the developer name.

  • Schema.DescribeSObjectResult.getRecordTypeInfosByDeveloperName()
  • Schema.RecordTypeInfo.getDeveloperName()

See Also
IdeaExchange: Get RecordTypeInfos by API name method

1
  • 2
    When you link to a resource (either in a question or an answer), you should include relevant content within your post so that A) it is obvious to which content you refer, B) your answer will still add value if the link goes dead, and C) users of this exchange can benefit from your answer without leaving the site. I have done so for you here. Please take this example and apply it moving forward. Thanks!
    – Adrian Larson
    Commented May 16, 2018 at 13:09
3

Short answer: There's no way to do that.

Long answer: Currently, the only way to access the developer name is to query for it. I'd recommend using an utility class with a static map so you can make just one call per execution.

You can also vote on this idea.

0

Below code can be used to get recordtypeDevelopername without SOQL

Map<String,Schema.RecordTypeInfo> recordinfodetails = Schema.SObjectType.case.getRecordTypeInfosByName();

for(Schema.RecordTypeInfo val : recordinfodetails.values()){
     system.debug(val.getRecordTypeId() +' '+ val.getDeveloperName());

}

You must log in to answer this question.

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