rspec/rules/S5387/apex/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

44 lines
1.4 KiB
Plaintext

== Why is this an issue?
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
[source,apex]
----
Id RTId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Asia Service').getRecordTypeId();
----
=== Compliant solution
[source,apex]
----
Id RTId = Schema.SObjectType.Case.getRecordTypeInfosByDeveloperName().get('Asia_Service').getRecordTypeId();
----
== Resources
* 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[]