Synchronous and Asynchronous calls using Apex in Salesforce

Synchronous and Asynchronous calls using Apex in Salesforce

Apex can be executed synchronously or asynchronously.

Synchronous:
In a Synchronous call, the thread will wait until it completes its tasks before proceeding to next. In a Synchronous call, the code runs in single thread.

Example:

  1. Trigger
  2. Controller Extension
  3. Custom Controller

Asynchronous:
In a Asynchronous call, the thread will not wait until it completes its tasks before proceeding to next. Instead it proceeds to next leaving it run in separate thread. In a Asynchronous call, the code runs in multiple threads which helps to do many tasks as background jobs.

Example:

  1. Batch Apex
  2. @future Annotation
  3. Queueable Interface
  4. Scheduled Apex

Leave a Reply