APEX-Q01โ˜… Must-prepareConceptual IntermediateApex & triggers#apex#async-apex

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.

NeedChoiceWhy
Callout or follow-up work after a save; objects as input; chaining; monitoringQueueableJob ID, complex parameters, chaining, Finalizers, delay and duplicate control
Process millions of records in chunksBatch ApexQueryLocator up to 50 million rows, chunk-level transactions, finish step
Large volumes but batch slots are busy, or more flexible chunkingApex Cursor + chained QueueableNo batch slot used; fetch chunks across a chain
Run at a time or on a scheduleScheduled Apex that starts a batch or queueableKeeps timing separate from processing
Producer shouldn't wait for or know the consumerPlatform EventsSeparate subscriber transaction with retries
Tiny legacy fire-and-forget@futureStill 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.