Apex Coding Standards
Author: callinj Name: Joe Callin Title: Sr. Salesforce Developer Email: joe@jcallin.dev
Introduction
Purpose
This document establishes comprehensive coding standards and best practices for Apex development within your Salesforce project or codebase. These standards ensure consistency, maintainability, security, and quality across all Apex code.
Scope
These standards apply to all Apex classes, triggers, and related code in the project. All code must comply with these standards and pass Salesforce Code Analyzer validation using the project's ruleset.
Related Documentation
- Project code prefix - Choosing, recording, and applying your team's Apex and LWC prefix
- Code Analyzer Compliance - Detailed Code Analyzer rules and compliance requirements
- Apex Testing Standards - Test coverage and testing patterns
- Testing Policy - Org-wide testing policy and coverage requirements
- Git Branching Strategy - Git branching and merge strategy for the repository
Topics
- Naming and Organization - Naming conventions, class structure, and package organization
- Null Handling and Errors - Safe navigation, collection initialization, and error handling patterns
- Security - Sharing models, CRUD/FLS enforcement, SOQL injection prevention
- Methods and Structure - Method visibility, return patterns, and frontend integration
- Documentation - ApexDoc comments, inline comments, and documentation requirements
- Code Quality - Code style, complexity limits, and performance optimization
- Testing - Apex testing standards, data management, and mocking patterns
- Maintenance - Logging, debugging, code maintenance, and Code Analyzer compliance
Future Considerations / Roadmap
The following topics are identified for future discussion and potential addition to these standards:
- String Handling Methods - Guidelines for
String.isBlank()vsisEmpty()vsisNotBlank()- when to use each - Switch Statements -
switch onvs if/else chains - when to use each pattern - Type Checking -
instanceofpatterns and type casting best practices - Collection Selection - When to use
ListvsSetvsMap- selection criteria and patterns - Schema Patterns - Detailed guidelines for
Schema.getGlobalDescribe(),getSObjectType(),getDescribe()usage - Governor Limit Checking -
Limitsclass usage patterns and best practices - Async Patterns -
@Future,Queueable,Batchable,Schedulablepatterns (even if not currently used) - Callout Patterns - HTTP callouts, named credentials usage (ruleset mentions
ApexSuggestUsingNamedCred) - Transient Keyword - For
@AuraEnabledproperties to reduce view state - Property Getters/Setters - Custom getter/setter patterns and when to use them
- JSON Serialization -
JSON.serialize()/deserialize()patterns and best practices - Date/Time Handling - Date/Datetime/Time patterns and timezone considerations
These items should be discussed and added to the standards documentation as needed based on project requirements and codebase evolution.
Change History
Version 2.1 - 2026-03-26
- Added and refined hub guidance, related-document links, and topic structure details.
- Expanded roadmap context while keeping the Apex standards split-model introduced in 2.0.
Version 2.0 - 2026-03-25
- Restructured: split into hub page with topic subpages
Version 1.0 - 2026-01-14
- Initial release of Apex coding standards documentation
Last Updated: 2026-03-26 Version: 2.1