Print this page

What are the differences between the different possible jobs processed in the 'AsyncApexJob' object?

Knowledge Article Number 000228389
Description In Salesforce, records in the 'AsyncApexJob' table represents Apex jobs to run asynchronously when resources are available. Examples of these asynchronous Apex jobs include Future Methods, Queueable Apex, Batch Apex and Scheduled Apex. If we examine the SOAP API guide for the 'AsyncApexJob' object, we see these mentioned asynchronous jobs represented under the 'JobType' field, however we also observe a number of other job types such as 'ApexToken', 'TestWorker' and 'TestRequest'. Whilst standard asynchronous jobs such as the aforementioned Future, Queueable, Batch and Scheduled are widely documented, what about the others? 
Resolution As per the documentation on the 'AsyncApexJob' object, under the 'JobType' field there are currently nine types of asynchronous Apex jobs, these are as follows:
  • Future
  • SharingRecalculation
  • ScheduledApex
  • BatchApex
  • BatchApexWorker
  • TestRequest
  • TestWorker
  • ApexToken
  • Queueable
The following is a brief explanation of each:
FutureA 'Future' method represents an asynchronous apex method annotated as an @future method. Future methods are used to execute long-running operations such as callouts to external Web services or any operation requiring its own thread and to run in its own time
SharingRecalculationA 'SharingRecalculation' job represents a Batch Apex class (class that implements Batchable interface via implements Database.Batchable) used to recalculate the Apex managed sharing for a specific custom object. A 'SharingRecalculation' can be associated with a custom object via the custom object detail page and initiated via 'Recalculate Apex Sharing'
ScheduledApexA 'ScheduledApex' job represents an asynchronous Apex class using the Schedulable interface via implements Schedulable. Using Scheduled Apex allows for the invocation of Apex classes to run at specific times when resources are available
BatchApexA 'BatchApex' job represents an asynchronous Apex class using the Batchable interface via implements Database.Batchable. Using Batch Apex allows for the asynchronous processing of a long running process on a large data volume by breaking the job into manageable chunks to be processed separately
BatchApexWorkerUsed internally by Salesforce. For each 10,000 'AsyncApexJob' records, Apex creates an 'AsyncApexJob' record of type 'BatchApexWorker' for internal use. When querying for all 'AsyncApexJob' records, we recommend that you filter out records of type 'BatchApexWorker' using the 'JobType' field to avoid returning one more record for every 10,000 'AsyncApexJob' records
TestRequestEvery time Apex test(s) are run asynchronously from the UI or from Apex code, the system creates a parent 'AsyncApexJob' with 'JobType' set as 'TestRequest'. Customers can also execute a SOQL query to check the status of overall test request
TestWorkerA 'TestWorker' job is used only internally by Salesforce, and is not saved in the database 
ApexTokenAn 'ApexToken' job is used for Flex Queue enabled organizations. From Winter '16 onwards, the flex queue is enabled by default for all organizations. If an Apex code block invokes Database.executeBatch(),instead of accepting the job directly into Salesforce's queueing system, an 'ApexToken' Job is submitted to the queue. For any batch job that a user submits, a token job is created internally. However, if the maximum number of queued batch jobs in the batch job queue has been reached, the new batch job is placed in a 'Holding' state in the flex queue. 

'ApexToken' is our internal mechanism for managing system resources. When a token job gets picked up by the system for execution, it's an indication that the system can take in more jobs from the flex queue. 

Note: Every organization has only limited number of 'ApexToken' jobs. This token mechanism allows organizations to submit more batch jobs (maximum is a 100), however only some of them could be running in parallel on the Salesforce platform. 
QueueableA 'Queueable' job represents an asynchronous Apex class using the Queueable interface via implements Queueable. Using the Queueable interface, allows users to manage and monitor asynchronous Apex jobs

promote demote