Difference between synchronous and asynchronous in apex

Synchronous Apex :-

Synchronous term means existing or occurring at the same time. Synchronous Apex means entire Apex code is executed in one single go.

Asynchronous Apex :-

Asynchronous term means not existing or occurring at the same time. Asynchronous apex is executed when resources are available. So any calling method which calls Asynchronous apex wont wait for outcome of Asynchronous call. Calling method will go on further execution in code. And Asynchronous execution happens in separate thread and then it will return to main program.

An async call is queued up in Salesforce and run on a separate thread of execution. At this point it becomes decoupled from the calling action. That also means the calling action won’t block and wait for a response from the asycn call. Using the future annotation identifies methods that are executed asynchronously. They must also be static methods. There are some considerations to know when using async methods.

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

--

--

--

Tech enthusiastic, life explorer, single, motivator, blogger, writer, software engineer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

My Journey Into Being A Machine Learning Engineer or Data Scientist

TimeCoinProtocol Presentation From CEO

How To Send Email Using Nodemailer

WordPress vs Bootstrap: Which One is the Best for Your Business?

Principal Off Campus Drive 2022 | Cloud Developer | BE, B.Tech | Apply Now

Apache Airflow on Docker With AWS S3

5 must-have command line Kubernetes tools

How to deploy your Flask App to AWS EC2 instance with Nginx, Gunicorn

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
TechGuy

TechGuy

Tech enthusiastic, life explorer, single, motivator, blogger, writer, software engineer

More from Medium

Limit your technical debt and secure your code base using MegaLinter

OutSystems DevOps Model Series: 1-Introduction

Never “Never write tests for your app”

A magical place called ‘Barrack’