Apex Trigger Framework and Custom Metadata Types: Zero-Downtime Logic Switching
0 reputation · 22 May 2023, 14:26 UTC
Updating application logic in an Apex trigger without downtime using a Trigger Framework pattern combined with Custom Metadata Type feature flags introduces an unresolved integration boundary between synchronous trigger execution and asynchronous processing.
The platform does not guarantee execution order when multiple triggers exist on the same object, which complicates deterministic behavior during a logic switch. Additionally, asynchronous Apex operations such as Future, Queueable, or Batchable jobs may read the feature flag at a different time than the initiating transaction, creating a window where old and new logic operate on overlapping data. Governor limits on CPU time and heap size further constrain how transition states can be validated during bulk operations.
What is the recommended pattern for ensuring that asynchronous Apex jobs spawned during a feature-flag transition consistently apply the intended logic version? How does Salesforce resolve trigger execution order for multiple triggers on a single object when the underlying logic is controlled by Custom Metadata? What state-management practices prevent data inconsistency when toggling Apex logic via metadata during active bulk operations?