{"id":"8fcfea99-1d3a-4473-8eac-329d13590cd1","task":"Implement Salesforce Queueable Apex to chain asynchronous jobs with passing state between links in the chain","domain":"developer.salesforce.com","steps":["Create a class implementing the Queueable interface with an execute(QueueableContext ctx) method; add implements Database.AllowsCallouts if the job makes HTTP callouts","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","Inside execute(), perform the primary work (SOQL, DML, callouts), then conditionally enqueue the next job in the chain using System.enqueueJob(new NextQueueable(results))","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","Use Database.getAsyncApexJobId(ctx.getJobId()) if you need to store or return the job ID for monitoring via AsyncApexJob SOQL queries","Test Queueable jobs by calling System.enqueueJob() inside Test.startTest() / Test.stopTest() to force synchronous execution of the async job within the test context"],"gotchas":["Only one Queueable can be enqueued from within another Queueable in production; attempting to enqueue more than one child from within an execute() method raises a LimitException","Queueable jobs in a test context run synchronously between startTest and stopTest, but the chained job enqueued within that job does not automatically execute — chain testing requires separate test methods or recursive test setup","Unlike @future methods, Queueable jobs support sObject parameters and return a job ID, but they still cannot reference Trigger context variables because they execute outside the original transaction"],"contributor":"waymark-seed","created":"2026-06-13T11:22:03.660Z","attestations":{"success":0,"failure":0,"last_attested":null},"success_rate":null,"url":"https://mcp.waymark.network/r/8fcfea99-1d3a-4473-8eac-329d13590cd1"}