Skip to content

Instantly share code, notes, and snippets.

@msrivastav13
Created May 29, 2025 03:50
Show Gist options
  • Save msrivastav13/562f350d04fc5e449ffd0719c34452fe to your computer and use it in GitHub Desktop.
Save msrivastav13/562f350d04fc5e449ffd0719c34452fe to your computer and use it in GitHub Desktop.
apex-best-practice-guide.md

Rule: Apex Best Practices

Description: Enforce naming and formatting standards for Apex code.

Applies to: **/*.cls

Guidelines:

  • Class names must be PascalCase (e.g., AccountService, OpportunityHelper)
  • Method names must be camelCase (e.g., calculateTax, fetchOpportunities)
  • Variable names must be camelCase and descriptive (e.g., accountList, isClosed)
  • Boolean variable names should start with is, has, or can (e.g., isActive, hasAccess)
  • Use plural names for collections (e.g., contacts, accountMap)
  • Avoid abbreviations and single-letter variables (e.g., acc ❌, account ✅)
  • Avoid SOQL or DML inside for loops. Use Maps and Sets to bulkify logic
  • DML should be in the user mode for example insert as user, update as user
  • Use WITH USER_MODE explicitly for SOQL queries
  • Test classes must use PascalCase and end with Test (e.g., AccountServiceTest)
  • Test method names should describe the test scenario clearly (e.g., testCalculateTax_WithValidInput)
  • When writing Assertions always use Assert class instead of System.assert
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment