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);
    }
}
----


== See

* 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)

include::message.adoc[]

include::highlighting.adoc[]

endif::env-github,rspecator-view[]
