
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.
55 lines
1.3 KiB
Plaintext
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[]
|