28 lines
1.1 KiB
Plaintext
28 lines
1.1 KiB
Plaintext
Using ``++getRecordTypeInfosByName()++`` requires you to pass the Record Type Name. A Record Type Name is a label, which means that it can be easily changed by an administrator. When this happens, the code will simply stop working until a developer updates the Record Type Name. Even worse, Labels are usually translated in multi-language environments, which will again make the code fail.
|
|
|
|
|
|
The method getRecordTypeInfosByDeveloperName() also enables you to get the Record Type Id, but it requires instead a Record Type API Name, which is rarely changed.
|
|
|
|
|
|
Thus it is safer to use ``++getRecordTypeInfosByDeveloperName()++`` than ``++getRecordTypeInfosByName()++``.
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
----
|
|
Id RTId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Asia Service').getRecordTypeId();
|
|
----
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
----
|
|
Id RTId = Schema.SObjectType.Case.getRecordTypeInfosByDeveloperName().get('Asia_Service').getRecordTypeId();
|
|
----
|
|
|
|
|
|
== See
|
|
|
|
* https://smukov.github.io/blog/2018/06/09/Record-Type-Id-By-Developer-Name/[Get Record Type Id by Developer Name]
|
|
|