Skip to content

Scalability and Performance

Abdelhakim Mouttaqui edited this page May 16, 2025 · 1 revision

The Apex Orbit Framework (AOF) is designed with scalability and performance as primary considerations, especially for Salesforce organizations with a large user base and significant data volumes. Key aspects contributing to this are:

Strict Bulkification:

Every layer of the framework, from the AOF_TriggerHandler to Domain, Service, and Selector classes, is designed to operate on collections of records (e.g., List<SObject>, Map<Id, SObject>). This is fundamental to avoiding governor limit exceptions related to DML statements, SOQL queries, and CPU time in a bulk processing context.

Selective and Efficient Queries:

  • The Selector Layer promotes writing selective SOQL queries by encouraging the use of specific WHERE clauses and querying only the necessary fields required by the business logic. This reduces database load and improves query performance.
  • The AOF_Application_Selector base class provides utilities to build field lists dynamically while respecting FLS, ensuring only accessible and queryable fields are included.

Optimized Looping and Data Handling:

  • The framework design discourages SOQL queries or DML statements inside loops, a common cause of governor limit issues.
  • Efficient use of Map collections is encouraged for accessing related data or comparing old and new record values, which significantly improves processing time for large datasets.

Centralized DML with Unit of Work:

The AOF_Application_UnitOfWork component aggregates all DML operations and executes them in a minimal number of statements (e.g., one insert for all new records of a type). This drastically reduces DML statement consumption, a critical governor limit.

Asynchronous Processing for Large Tasks:

  • The Service Layer is the appropriate place to orchestrate asynchronous operations (Batch Apex, Queueable Apex, Future methods) for processes that are too large, too long-running, or might consume excessive resources if run synchronously. This helps in offloading heavy processing and improving responsiveness for users.
  • The error handling mechanism, utilizing Platform Events, is inherently asynchronous, ensuring that logging errors does not impact the performance of the primary transaction.

Efficient Trigger Management:

The single trigger per SObject pattern, combined with the AOF_TriggerHandler, provides a streamlined and efficient way to manage trigger execution. It avoids the complexities and potential performance issues of multiple triggers on the same SObject vying for execution order or repeating logic.

Custom Settings and Metadata for Configuration:

The framework encourages the use of Custom Settings or Custom Metadata Types for configurable parameters such as bypass flags, operational thresholds, feature toggles, or endpoint URLs. This allows for administrative control and modification of behavior without code changes, enhancing flexibility and maintainability.

Governor Limit Awareness and Monitoring:

While the framework is designed to operate well within governor limits, the integrated error logging (via AOF_ErrorHandlerService) can capture and log limit exceptions if they occur. This provides valuable diagnostic information for identifying and addressing performance bottlenecks in complex implementations.

Lightweight Design:

AOF avoids unnecessary overhead and complexity, focusing on providing a lean yet powerful set of tools. This contributes to better overall performance as there are fewer layers of abstraction or heavy objects to instantiate and manage for simple operations.

By adhering to these principles, AOF provides a robust foundation that can scale with the evolving needs of a large Salesforce organization, ensuring efficient processing and optimal performance.

Clone this wiki locally