Skip to content

Collect/dispatch transaction buffer for coordinating async work #49

Description

@Mateusz7410

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions