Inconsistent naming Apex variables
Why is this an issue?
Naming conventions help drive consistency across the application, making source code easier to read and understand. When variables and constants don't follow established naming patterns, code becomes harder to read and maintain.
This rule checks variables and constants in all Apex classes and triggers. This includes test classes, which are read and maintained like any other code.
Examples
Example of incorrect code:
public class AccountService {
public static final String ABORT__TRANSACTION = 'abort';
public void processAccount(Account account) {
String RESULT = 'success';
}
}
Example of correct code:
public class AccountService {
public static final String ABORT_TRANSACTION = 'abort';
public void processAccount(Account account) {
String result = 'success';
}
}
How can I fix violations?
Apply consistent naming conventions:
Variables: Use camelCase (e.g.,
accountName,recordCount).Constants: Use UPPER_SNAKE_CASE (e.g.,
MAX_RETRY_COUNT,DEFAULT_STATUS).
When should I disable this rule?
You may dismiss specific violations when your organization has intentionally adopted a different naming standard.
Resources
