What is Asynchronous Apex?

Asynchronous Apex is the process which runs in the background without the user having to wait for the process to finish.

We use asynchronous apex mostly when callouts to external systems is required, code needs to be run at some particular time, higher Governor Limits are required for some operation.

Key benefits of Asynchronous Apex in Salesforce include:

  • User efficiency
  • Scalability
  • Higher Governor Limits

Asynchronous apex can be implemented using different techniques which includes Future Methods, Batch Apex, Queueable Apex and Scheduled Apex. Overview of the common scenarios where these can be used in Salesforce:

Asynchronous Process TypeExamples
Future Methods1. Callouts to external Web services
2. Operations which can run in their own thread
3. To prevent the mixed DML error
Batch Apex1. When processing is required on lots of records
2. Jobs that need larger query results
Queueable Apex1. Processing on Non-primitive data types
2. Chaining of jobs
3. To start a long-running operation and get an ID for it
Scheduled ApexWhen a process needs to be run at some specific time
Open the link to each process type for hands-on examples.