rspec/rules/S5387/apex/rule.adoc

44 lines
1.4 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
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
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,apex]
2021-04-28 16:49:39 +02:00
----
Id RTId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Asia Service').getRecordTypeId();
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,apex]
2021-04-28 16:49:39 +02:00
----
Id RTId = Schema.SObjectType.Case.getRecordTypeInfosByDeveloperName().get('Asia_Service').getRecordTypeId();
----
== Resources
2021-04-28 16:49:39 +02:00
* https://smukov.github.io/blog/2018/06/09/Record-Type-Id-By-Developer-Name/[Get Record Type Id by Developer Name]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
replace this call to "getRecordTypeInfosByName" by a call to "getRecordTypeInfosByDeveloperName"
endif::env-github,rspecator-view[]