Loading

Why a SOQL Count on AsyncApexJob Doesn't Match the "Async Apex Executions" Count on the Apex Jobs Page

Fecha de publicación: Oct 2, 2026
Descripción

Running a SOQL query to count asynchronous Apex activity created within a given time window, for example:

 
SELECT COUNT(Id) FROM AsyncApexJob WHERE CreatedDate >= :startDateTime AND CreatedDate <= :endDateTime

returns a much smaller number than the "Async Apex Executions" count shown on the Setup → Apex Jobs page for that same period.

Example: A batch job with 500 chunks shows 500 Async Apex Executions on the Apex Jobs page, but a SOQL count on AsyncApexJob for the same run returns only a handful of records — the exact number varies by run.

Cause

AsyncApexJob is a job-tracking object, not an execution log. For a single Batch Apex run, Salesforce creates a small set of AsyncApexJob "housekeeping" records to represent and manage the job as a whole, using job types such as:

  • BatchApex — represents the batch job (more than one can appear if the job is internally restarted/requeued to continue processing, or if finish() triggers job chaining).
  • BatchApexWorker — the internal process that dispatches chunks to be executed.
  • ApexToken — an internal token used to manage the job's execution context (more than one can appear if the execution context is re-established partway through, e.g., after a requeue).

These housekeeping records don't multiply per chunk — the Apex Jobs page counts actual executions (one per chunk), so it scales with data volume while AsyncApexJob's row count does not.

Solución
  • To count jobs run: query AsyncApexJob
  • To determine the number of batch executions/chunks processed for a specific job (matching what the Apex Jobs page shows), use the JobItemsProcessed and TotalJobItems fields on the corresponding AsyncApexJob parent record, rather than counting rows.
  • To monitor daily Async Apex Execution governor limits, use the Apex Jobs page 
Número del artículo de conocimiento

005460516

 
Cargando
Salesforce Help | Article