Local variable or parameter is not camelCase
ID |
apex.maintainability.naming_identifier_style |
Severity |
info |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Naming |
Language |
Apex |
Description
Reports a local variable, a loop variable, a catch parameter or a method parameter whose name does not follow the Apex convention of camelCase - a lowercase first letter and no underscores. Fields and constants have their own conventions and are not reported here, and neither are the platform context parameters BC, SC and QC, which every Salesforce example spells in uppercase.
Rationale
Locals and parameters are the names a reader meets most often, and they are the ones with the least context: there is no declaration header nearby to explain them. When some are account_id, some AccountId and some accountId, the reader stops reading the logic and starts pattern-matching the spelling - and in a case-insensitive language a near-miss spelling can silently refer to a different declaration than the one intended.
The following code illustrates the pattern detected by this rule:
public class NamingIdentifiers {
private Integer Field_Not_Reported;
public void work() {
// FLAGGED: Local variable or parameter is not camelCase
Integer Retry_Count = 0;
// FLAGGED: Local variable or parameter is not camelCase
String AccountName;
Integer retryCount = 0;
String customerName;
System.debug(Retry_Count + retryCount + AccountName + customerName);
}
// FLAGGED: Local variable or parameter is not camelCase
public void handle(String Account_Name, Integer attempts) {
System.debug(Account_Name + attempts);
}
public void loops(List<Account> accts) {
// FLAGGED: Local variable or parameter is not camelCase
for (Account A : accts) {
System.debug(A);
}
// FLAGGED: Local variable or parameter is not camelCase
for (Integer I = 0; I < 3; I++) {
System.debug(I);
}
// FLAGGED: Local variable or parameter is not camelCase
try {
insert accts;
} catch (DmlException DmlEx) {
System.debug(DmlEx);
}
for (Account a : accts) {
System.debug(a);
}
}
global void execute(Database.BatchableContext BC, List<Account> scope) {
System.debug(scope.size());
}
public void handleOk(String accountName, Integer attempts) {
System.debug(accountName + attempts);
}
}