rspec/rules/S5390/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

55 lines
1.3 KiB
Plaintext

== Why is this an issue?
Its a best practice to avoid hardcoding of text strings in Apex. Ideally those text should be stored in a Custom Label and referenced via those in the code. This enables administrators and translators to update the messages without modifying the code. It also enables the translation of those text in international organizations.
This rule raises an issue when a call to the ``++sObject.addError++`` method is given a hardcoded string.
=== Noncompliant code example
[source,apex]
----
public class MyClass{
public static myMethod(Case mycase) {
mycase.addError('This is a hardcoded error');
}
}
----
=== Compliant solution
[source,apex]
----
public class MyClass{
public static myMethod(Case case) {
mycase.addError(System.Label.caseErrorMessage);
}
}
----
== Resources
* https://help.salesforce.com/articleView?id=cl_about.htm&type=5[Custom Labels]
* https://developer.salesforce.com/docs/atlas.en-us.198.0.apexcode.meta/apexcode/apex_methods_system_sobject.htm[sObject Class]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Replace this hardcoded message with a Label
=== Highlighting
The hardcoded string
endif::env-github,rspecator-view[]