Advanced 25 min read

Async Limits and Monitoring

By the end of this lesson, you'll be able to:

  • Recognize the specific limits on queued and running async jobs
  • Monitor a running job's status via AsyncApexJob
  • Explain why async limits exist for the same reason as Module 25's synchronous ones

Prerequisites: "Scheduled Apex"

The limits that apply specifically to async

Limit Value
Queueable jobs per transaction 50 (1 if chained from within another Queueable, in most contexts)
Batch jobs queued or active at once 5
Future method calls per transaction 50

These are genuinely separate from Module 25's synchronous-transaction limits — a transaction can enqueue up to 50 Queueable jobs, even though it could only run 100 SOQL queries synchronously; they're different budgets for different kinds of work.

Monitoring a running job

Id jobId = Database.executeBatch(new UpdateStaleAccountsBatch(), 200);

AsyncApexJob job = [
    SELECT Id, Status, JobItemsProcessed, TotalJobItems, NumberOfErrors
    FROM AsyncApexJob
    WHERE Id = :jobId
];

System.debug('Status: ' + job.Status + ', Progress: ' + job.JobItemsProcessed + '/' + job.TotalJobItems);

Database.executeBatch returns the job's Id, and AsyncApexJob (a real Salesforce object, queryable with regular SOQL, Module 20) reports its live status — Queued, Processing, Completed, or Failed — along with how many chunks have finished and how many errors occurred.

The same reasoning as Module 25, applied here

Async limits exist for the exact reason Module 25 gave for synchronous ones: shared, multi-tenant infrastructure. Without a cap on concurrent batch jobs, one org's runaway async processing could degrade the platform's shared job-processing capacity for every other org — the same protective principle, just applied to a different resource (concurrent background jobs, not per-transaction queries).

Exercise

Write a query checking the Status and NumberOfErrors for a specific AsyncApexJob by its Id.

Show hint

SELECT Status, NumberOfErrors FROM AsyncApexJob WHERE Id = :jobId

APEX

Async Limits and Monitoring Quiz

1. How many Batch Apex jobs can be queued or active at once, per org?

Log in to submit the quiz and save your score.

My Notes

Log in to keep private notes on this lesson.

Questions about this lesson

No questions yet — be the first to ask.

Log in to ask a question about this lesson.

Summary

Asynchronous Apex has its own set of governor limits — different numbers from the synchronous limits in Module 25, but rooted in the exact same multi-tenant reasoning.