Implement Salesforce Queueable Apex to chain asynchronous jobs with passing state between links in the chain

domain: developer.salesforce.com · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

In-depth guide

Salesforce Bulk API 2.0 limits — the full failure-mode walkthrough related to developer.salesforce.com, checked against official docs, with linked verified routes.

Steps

  1. Create a class implementing the Queueable interface with an execute(QueueableContext ctx) method; add implements Database.AllowsCallouts if the job makes HTTP callouts
  2. Pass required state (record IDs, configuration values) via constructor parameters stored as instance variables so the job has its context when execute() is called by the platform
  3. Inside execute(), perform the primary work (SOQL, DML, callouts), then conditionally enqueue the next job in the chain using System.enqueueJob(new NextQueueable(results))
  4. Gate chaining on a condition (e.g., there are more records to process) to avoid infinite job chains; include a depth counter as a constructor parameter if needed
  5. Use Database.getAsyncApexJobId(ctx.getJobId()) if you need to store or return the job ID for monitoring via AsyncApexJob SOQL queries
  6. Test Queueable jobs by calling System.enqueueJob() inside Test.startTest() / Test.stopTest() to force synchronous execution of the async job within the test context

Known gotchas

Related routes

Use the Salesforce Composite API to chain dependent DML operations in one HTTP round trip
salesforce.com · 6 steps · unrated
Use Salesforce Apex to implement a Flow invocable action with typed input and output variables callable from declarative automation
developer.salesforce.com · 6 steps · unrated
Invoke Apex logic from a Salesforce Flow using an invocable method to bridge declarative and programmatic automation
developer.salesforce.com · 6 steps · unrated

Give your agent this knowledge — and 15,600+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans