Asynchronous Programming in Salesforce

Sharing is Caring

What is Asynchronous Programming?

In synchronous programming, each step is performed one after the previous one is finished executing. This means that each step blocks the next step.

In a lot of cases, we probably don’t necessarily need to do everything in order. In asynchronous programming, steps can all execute in parallel and/or in really any order.

Salesforce queues all asynchronous calls on separate execution threads. This basically stops the caller from blocking and waiting for a response.

Asynchronous processing provides some really good advantages like

  • Scalability: because the calls are queued up there’s a lot less limits that Salesforce Programmers need to be worried about.
  • User Efficiency: employees, customers, and partners don’t necessarily need to sit around waiting for a long running process to finish.

Common Use Cases

I commonly use asynchronous methods whenever I need to do a callout from a trigger when some field has been updated. For example at eWAY, we needed to do a credit check when a perspective merchant reached a certain stage in the registration process.

Different Types of Asyncronous Processes

Salesforce provides a few different kinds of ways to do asynchronous programming each with their own advantages and disadvantages. One of the most common ways is to use a future method.

Sharing is Caring

Brian is a software architect and technology leader living in Niagara Falls with 13+ years of development experience. He is passionate about automation, business process re-engineering, and building a better tomorrow.

Brian is a proud father of four: two boys, and two girls and has been happily married to Crystal for more than ten years. From time to time, Brian may post about his faith, his family, and definitely about technology.