Asynchronous Apex

Synchronous and Asynchronous in Salesforce?

What is Synchronous and Asynchronous 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:
Trigger
Controller Extension
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:
Batch
@future Annotation

Asynchronous Apex is used to run process in a separate thread at later time. It is process or function that executes a task “in the back ground” without the user having to wait for the task to finish.

We can typically use asynchronous process for callouts to external systems, operations that require higher limits, and code that needs to run at a certain time.

Benefits of Asynchronous process are User efficiency, Scalability and higher limits.

There different ways to implement Asynchronous process in Apex.

  1. Future methods
  2. Batch Apex
  3. Queueable Apex
  4. Scheduled Apex

Comments

Popular posts from this blog

Security model

EVENTS IN Lightning Web Components

Lightning web Components.