Does getRecordTypeInfosByName() look at the developer name or the record type label?

154    Asked by DianeCarr in Salesforce , Asked on Jun 2, 2023

 I used recordtypeId == '012A0000000rI1T' in a method to query if my Account record type "Practice Account" was what I wanted.

I've been reading that this is not a best practice and I should use something like:

Schema.SObjectType.Account.getRecordTypeInfosByName().get('Practice Account').getRecordTypeId()

My question is does getRecordTypeInfosByName() look at the developer name or the record type label? I can't find any info about what it looks like.

Answered by dia shrinidhi

It's not entirely clear in the documentation on the gerRecordTypeInfosByName() method, but the documentation does make a mention of using the 'label'

getRecordTypeInfosByName()
Returns a map that matches record labels to their associated record type. The current user is not required to have access to a record type to see it in this map.
I don't know if there are any standard objects that have record type names that include a space, but I know that my org has a few.
Checking my codebase revealed the following line
Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Change Order').getRecordTypeId();
As API names cannot contain spaces, and I've had this particular line of code in production for coming up on 3 years, we can conclude that the map returned by getRecordTypeInfosByName() is indeed keyed on the record type's label.


Your Answer

Interviews

Parent Categories