Motivation
When several services in one transaction each want to enqueue async work, they
either enqueue separately (scattered enqueues, no coordination) or have to thread
a shared builder through every call. A transaction-scoped buffer that collects
jobs and enqueues them once at the orchestration boundary would keep trigger-side
services declarative: each service states the work it needs, the orchestrator
decides when it is created.
Proposal
// from service A
Async.collect(new SendWelcomeJob(contacts));
// from service B
Async.collect(new ReviewContactJob(contactIds));
// once, at the trigger handler / service boundary
Async.dispatch();
collect buffers QueueableJob instances in the current transaction.
dispatch enqueues everything collected as one chain and clears the buffer.
- Optional dedupe by a caller-supplied key, so the same logical job collected
twice collapses to one.
Notes
- Complements the existing incremental
Async.queueable() builder; this is a
static, transaction-scoped buffer any service can add to without holding a
builder reference.
dispatch on an empty buffer is a safe no-op.
Acceptance criteria
- New static entry points; existing
global signatures untouched.
- Apex tests: multi-service collect, single dispatch, optional dedupe, empty
dispatch no-op.
- Docs.
Motivation
When several services in one transaction each want to enqueue async work, they
either enqueue separately (scattered enqueues, no coordination) or have to thread
a shared builder through every call. A transaction-scoped buffer that collects
jobs and enqueues them once at the orchestration boundary would keep trigger-side
services declarative: each service states the work it needs, the orchestrator
decides when it is created.
Proposal
collectbuffersQueueableJobinstances in the current transaction.dispatchenqueues everything collected as one chain and clears the buffer.twice collapses to one.
Notes
Async.queueable()builder; this is astatic, transaction-scoped buffer any service can add to without holding a
builder reference.
dispatchon an empty buffer is a safe no-op.Acceptance criteria
globalsignatures untouched.dispatch no-op.