2

We have below describe call to get the record type id by name.

Id recordTypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('RECORD_TYPE_NAME_NOT_DEVELOPER_NAME').getRecordTypeId();

This gives the id of the record but this logic is based on label of the record type instead of developer name. That means if we change the Label of record type then any code using such mechanism will break.

I know we can make a query to get the record type id by developer name but that will cost me a SOQL which I don't want to.

Is there any describe call to get the record type id by developer name without making the SOQL?

  • Why it was marked as a duplicate? This is completely opposite question. Previous one is about 'Getting Developer Name By Id' This on is about 'Getting ID by Name' – Yury Bondarau Sep 18 '19 at 15:08
3

Seems like the APIs are not supporting this, but there is an Idea for exactly this use case: Get RecordTypeInfos by API name method

Some related questions:

| improve this answer | |
  • 1
    This is under review, so at least there's Hope for the future. – sfdcfox Nov 13 '17 at 23:04
  • I thought I saw a tweet that there would be some progress in an upcoming release, but I can't recall exactly what it said. – Adrian Larson Nov 13 '17 at 23:38
  • 1
    @AdrianLarson Yeah, someone leaked a pic of the Apex Code road map. Forward-Looking Statement and all that, but here's hoping. – sfdcfox Nov 13 '17 at 23:44
  • Thank you. I think then we need to wait for salesforce to provide such methods. – Kiran Machhewar Nov 14 '17 at 3:01
  • Now you can use getRecordTypeInfosByDeveloperName() which was made available in Summer'18. developer.salesforce.com/docs/atlas.en-us.apexcode.meta/… – MikeA Aug 6 '19 at 11:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.