Constant is not named in UPPER_SNAKE_CASE
ID |
apex.maintainability.naming_constant |
Severity |
info |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Naming |
Language |
Apex |
Description
Reports a static final field whose name is not written in uppercase with underscores. The expected shape is ^[A-Z][A-Z0-9_]*$.
Rationale
A constant and a mutable field are read the same way at the point of use, so the casing is the only signal that a value is fixed for the life of the transaction. That matters most in the cases where someone is about to assign to it: an uppercase name makes the mistake obvious while reading, instead of at compile time or, worse, in a code review that never happened.
The following code illustrates the pattern detected by this rule:
public class NamingConstants {
// FLAGGED: Constant is not named in UPPER_SNAKE_CASE
private static final Integer maxRetries = 3;
// FLAGGED: Constant is not named in UPPER_SNAKE_CASE
public static final String DefaultRecordType = 'Standard';
private static final Integer MAX_RETRIES = 3;
public static final String DEFAULT_RECORD_TYPE = 'Standard';
private static Integer retryCounter = 0;
private Integer instanceField = 1;
}