Future, Queueable, Batch or Scheduled Apex: when do you use each?
Your confidence:Not rated
Model answer
Start from what the work needs, not from the tool.
| Need | Choice | Why |
|---|---|---|
| Callout or follow-up work after a save; objects as input; chaining; monitoring | Queueable | Job ID, complex parameters, chaining, Finalizers, delay and duplicate control |
| Process millions of records in chunks | Batch Apex | QueryLocator up to 50 million rows, chunk-level transactions, finish step |
| Large volumes but batch slots are busy, or more flexible chunking | Apex Cursor + chained Queueable | No batch slot used; fetch chunks across a chain |
| Run at a time or on a schedule | Scheduled Apex that starts a batch or queueable | Keeps timing separate from processing |
| Producer shouldn't wait for or know the consumer | Platform Events | Separate subscriber transaction with retries |
| Tiny legacy fire-and-forget | @future | Still works, but Queueable is recommended for new code |
Then mention operations: monitoring through AsyncApexJob, error handling (Finalizers, BatchApexErrorEvent), and idempotency so retries are safe.
โ Key points to hit
โ Red-flag answers
- 'Future is the fastest, so I always use it'
- Batch for 10 records
- Doing heavy processing inside the Schedulable class
- No mention of error handling
โช Follow-ups
Can you call a future method from a batch?
No. Future methods can't be called from batch or future contexts. Use a Queueable (one per execute is allowed) or handle the work in the batch itself.
What happens to queued jobs if the transaction rolls back?
They're discarded. Async jobs, like emails, are only released after a successful commit.