Skip to main content

Code reviews rule: Inconsistent naming Apex variables

Written by David Martin
Updated this week

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.

Examples

Example of incorrect code:

public class AccountService {
public static final String ABORT__TRANSACTION = 'abort';

public void ProcessAccount(Account MyAccount) {
String RESULT = 'success';
}
}

Example of correct code:

public class AccountService {
public static final String ABORT_TRANSACTION = 'abort';

public void processAccount(Account myAccount) {
String result = 'success';
}
}

How can I fix violations?

Apply consistent naming conventions:

  • Variables and parameters: 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

Did this answer your question?