Friday, July 28, 2017

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:

An asynchronous process can execute a task "in the background" without the user having to wait for the task to finish. Force.com features such as asynchronous Apex, Bulk API, and Reports and Dashboards use asynchronous processing to efficiently process requests.

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