Future vs Queueable vs Batch Apex: which async Apex should I use?
Quick answer
Use Queueable Apex for most new background work: it takes sObjects, returns a job ID and can chain. Use Batch Apex for large data sets, Schedulable Apex to run on a schedule, a future method only for small primitive-parameter jobs (Salesforce recommends Queueable instead), and platform events or Change Data Capture triggers for decoupled, event-driven processing. Answer the questions below for a ranked recommendation.
Choose an async approach
The wizard needs JavaScript. The comparison table, guidance and code below work without it.
The ranking is a heuristic: answers add or remove points. Only the exclusions are hard rules. Nothing you select leaves your browser.
Comparison of async Apex options
Limits below come from the governor limits reference. All asynchronous Apex also counts toward the daily asynchronous executions limit.
| Option | Accepts | Chaining | Monitoring | Key limits | Best for |
|---|---|---|---|---|---|
| @future method | Primitives and collections of primitives | No | No job ID (returns void) | 50 calls per transaction | Small, simple work, or a callout after DML, in existing code |
| Queueable Apex | sObjects and custom types as member variables | Yes, and finalizers can run follow-up logic | Job ID from System.enqueueJob | 50 enqueued in sync Apex, 1 from an async job | Most new background work, ordered steps, complex parameters |
| Batch Apex | Whatever the class holds; processes records in chunks via start, execute, finish | Start another job from finish | Job ID from Database.executeBatch | 5 queued or active, 100 in the flex queue | Large data volumes processed in chunks |
| Schedulable Apex | Runs a class on a cron schedule | Usually starts a batch or Queueable job | Scheduled job ID from System.schedule | 100. In Developer Edition orgs, the limit is 5 classes scheduled at once | Recurring work at set times |
| Platform event / CDC trigger | Event messages delivered to an Apex trigger | Not applicable; publish another event | Event bus and trigger logs | Trigger batches of up to 2,000 events; 150 immediate publish calls per transaction | Decoupled, event-driven reactions to data changes |
Limit rows: future calls, Queueable jobs, concurrent batch jobs (5), flex queue (100), scheduled classes.
When to use which
- Queueable Apex is the default for new background work. It accepts sObjects and custom types, returns a job ID, can start another Queueable job, and can use finalizers for follow-up logic.
- @future is for small, simple jobs where you only need primitive parameters, mostly in existing code. It cannot chain and gives no job ID.
- Batch Apex processes large data sets in chunks through
start,executeandfinish, with limits reset for eachexecutecall. - Schedulable Apex runs a class on a cron schedule. Keep it thin and let it start a batch or Queueable job.
- Platform events and Change Data Capture triggers suit decoupled, event-driven work where publishers do not know their subscribers. Triggers on these events receive batches of up to 2,000.
What the chooser recommends for common cases, generated by the same scoring code as the wizard:
- Send one record to an external system after an update: Queueable Apex, then @future method.
- Pass a list of sObjects to a follow-up step: Queueable Apex, then Batch Apex.
- Clean up two million records: Batch Apex, then Queueable Apex.
- Nightly sync of a few thousand records: Schedulable Apex, then Queueable Apex.
- Let other systems react to a change: Platform events / Change Data Capture trigger, then Queueable Apex.
Code skeletons
@future method with a callout
public class AccountSync {
@future(callout=true)
public static void send(Set<Id> accountIds) {
// Primitives only: query the records inside the method
List<Account> accounts = [SELECT Id, Name FROM Account WHERE Id IN :accountIds];
// ... make the HTTP callout ...
}
}
// Caller: AccountSync.send(new Set<Id>{ acc.Id }); Queueable with a finalizer
public class SyncJob implements Queueable, Database.AllowsCallouts {
private List<Account> accounts;
public SyncJob(List<Account> accounts) { this.accounts = accounts; }
public void execute(QueueableContext ctx) {
// ... callout or DML ...
// Optional: run follow-up logic however this job ends
System.attachFinalizer(new SyncFinalizer());
// Chain the next step (one job allowed from async Apex)
// System.enqueueJob(new NextStepJob());
}
}
public class SyncFinalizer implements Finalizer {
public void execute(FinalizerContext ctx) {
if (ctx.getResult() == ParentJobResult.UNHANDLED_EXCEPTION) {
// log ctx.getException()
}
}
}
// Caller:
Id jobId = System.enqueueJob(new SyncJob(accounts)); Batch Apex
public class ArchiveBatch implements Database.Batchable<SObject> {
public Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator('SELECT Id FROM Case WHERE IsClosed = true');
}
public void execute(Database.BatchableContext bc, List<Case> scope) {
// process one chunk; limits reset for each execute call
}
public void finish(Database.BatchableContext bc) {
// post-processing, or start another job
}
}
// Caller (scope of 200 is the default):
Id jobId = Database.executeBatch(new ArchiveBatch(), 200); Schedulable Apex
public class NightlyJob implements Schedulable {
public void execute(SchedulableContext sc) {
Database.executeBatch(new ArchiveBatch(), 200);
}
}
// Runs every day at 02:00. Cron: seconds minutes hours day-of-month month day-of-week
System.schedule('Nightly archive', '0 0 2 * * ?', new NightlyJob()); Platform event publish and trigger
// Publish (Order_Event__e is a platform event you define)
Order_Event__e evt = new Order_Event__e(Order_Id__c = order.Id);
Database.SaveResult sr = EventBus.publish(evt);
// Subscribe with an Apex trigger
trigger OrderEventTrigger on Order_Event__e (after insert) {
for (Order_Event__e e : Trigger.new) {
// react to the event
}
} Start any of these from a trigger handler rather than the trigger body; see the Apex trigger handler pattern.
Common mistakes
- Calling a future method or
System.enqueueJobinside a loop. Collect the IDs or records first and make one call (50 future calls and 50 enqueued jobs are the synchronous per-transaction limits). - Trying to enqueue several jobs from inside a Queueable. Asynchronous Apex can enqueue 1; build a chain.
- Passing sObjects to a future method. Pass IDs and query inside the method, or use Queueable.
- Forgetting
Database.AllowsCalloutson a Queueable or Batch class that makes callouts. - Starting a batch from a trigger for every save, which can exhaust the 5 concurrent batch slots.
- Putting heavy logic directly in a Schedulable class instead of starting a batch or Queueable job.
- Assuming batches or future calls run in a guaranteed order.
Official references
- Asynchronous Apex (Apex Developer Guide)
- Future methods (Apex Developer Guide)
- Queueable Apex (Apex Developer Guide)
- Batch Apex (Apex Developer Guide)
- Apex scheduler (Apex Developer Guide)
Frequently asked questions
What is the difference between future and Queueable Apex?
A future method must be static, return void and take only primitive parameters or collections of primitives. A Queueable class can hold sObjects and custom Apex types as member variables, returns a job ID from System.enqueueJob, and can start another Queueable job. Salesforce recommends Queueable Apex over future methods for new work.
Can I make a callout from a trigger?
Not directly in the trigger transaction. Move the callout into asynchronous Apex: a future method with @future(callout=true), or a Queueable or Batch class that implements Database.AllowsCallouts, and start it from the trigger or its handler.
What is the default batch size in Batch Apex?
If you do not pass a scope to Database.executeBatch, Salesforce splits the records from the start method into batches of 200. You can pass a different scope as the second parameter, for example Database.executeBatch(new MyBatch(), 100). Governor limits reset for each execute call.
How many Queueable jobs can I chain or enqueue?
In synchronous Apex you can add up to 50 jobs with System.enqueueJob in one transaction. From an asynchronous job, such as a running Queueable, you can add 1, so a chain is one job starting the next.
Can I call a future method from a batch or another future method?
No. The governor limit for future calls is 0 in batch and future contexts; 50 in queueable context. From a Queueable context you can call future methods, but a Queueable is usually the simpler choice there.
When should I use platform events instead of Queueable Apex?
Use platform events or Change Data Capture when publishers and subscribers should be decoupled, for example when several consumers react to the same change. An Apex trigger on the event receives batches of up to 2,000 events. For a single follow-up step in your own code, Queueable Apex is usually simpler.
Do future, Queueable, Batch and scheduled Apex share a limit?
Yes. They all count toward the org-wide asynchronous Apex method executions per 24-hour period, which is 250,000 or the number of applicable user licenses multiplied by 200, whichever is greater. For Batch Apex, start, execute and finish each count.
Related guides
More tools
SFDX Talk is unofficial documentation. It is not affiliated with, endorsed by, or sponsored by Salesforce, Inc. Salesforce changes its platform every release, so confirm against the official page before relying on a value.