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.

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:

  1. String Handling Methods - Guidelines for String.isBlank() vs isEmpty() vs isNotBlank() - when to use each
  2. Switch Statements - switch on vs if/else chains - when to use each pattern
  3. Type Checking - instanceof patterns and type casting best practices
  4. Collection Selection - When to use List vs Set vs Map - selection criteria and patterns
  5. Schema Patterns - Detailed guidelines for Schema.getGlobalDescribe(), getSObjectType(), getDescribe() usage
  6. Governor Limit Checking - Limits class usage patterns and best practices
  7. Async Patterns - @Future, Queueable, Batchable, Schedulable patterns (even if not currently used)
  8. Callout Patterns - HTTP callouts, named credentials usage (ruleset mentions ApexSuggestUsingNamedCred)
  9. Transient Keyword - For @AuraEnabled properties to reduce view state
  10. Property Getters/Setters - Custom getter/setter patterns and when to use them
  11. JSON Serialization - JSON.serialize()/deserialize() patterns and best practices
  12. 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