- SalesforceChaCha
- Posts
- π Why so synchronous? π
π Why so synchronous? π
Take your Apex to the next level!
Good morning, Salesforce Nerds! Are you looking for ways to implement asynchronous processing on the Salesforce platform? Not sure where to start? Check out this guide and boost your Apex skills!

Agenda for today includes
What is Asynchronous Apex?
Learn the Different types of Asynchronous Apex
Daily Principle
All the Memes
What is Asynchronous Apex?
Apex itself is a strongly typed, object-oriented programming language that gives developers all the necessary tools to write powerful applications on the Lightning Platform. Apex code can be initiated by system events, such as database triggers, web service calls, button clicks from a UI component, scheduled batches ... the list goes on and on.
While Apex provides many benefits for automating business processes, it is not a general-purpose programming language and, therefore, comes with its own set of restrictions. One such restriction is the ability to spawn threads to implement a form of asynchronous programming.
So how do you even do this? Any why? Well, have you been in that sweet developer flow-state, pounded out a solution your proud of, deployed to prod and then BAM! You immediately get smacked down by a Governor Limit? If not, give it time. It will happen! This is where you'll want to look into Asynchronous options. In many cases, moving your code to another thread on the platform will afford you extra cushion in these limits.
What are the options available if you're hit with a requirement that necessitates async processing?
Learn the different types of Asynchronous Apex
When it comes to Async processing with Apex you really have four (4) main options:
Future Methods - methods that run in the background when system resources are available. Use these if you have a long-running operation that you don't want your transaction to have to wait around for. These are also good for making a web service callout. Some things to note here - these methods must be static, can only return a void type, and any parameters must be primitive data types or a collection of primitive data types.
Batch Apex - Classes that are responsible for running jobs against large data sets that would otherwise blow through Governor Limits. Have a job you need to run that will perform some maintenance or clean-up on your database? Batch Apex is what you'll use.
Queueable Apex - Similar to future methods, but more robust. These are Apex classes that offer much more control over your asynchronous processes. The platform will give you an ID for your job that you can use to monitor it via the AsyncApexJob object. You can also pass complex data types (non-primitives) into this class for processing and chain jobs together!
Scheduled Apex - Schedule an Apex script to execute at a specific date & time. Combine this with Batch Apex to really unlock it's full potential!
Platform Events & CDC can also be used to execute Apex asynchronously, but since this isn't necessarily their primary function, we've left them off this list. We'll circle back around to them real soon!
Daily Principle
"Code is clean if it can be understood easily β by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability." β Robert C. Martin
As Uncle Bob says, even bad code can function. But if code isnβt clean, it can bring a development organization to its knees. Every year, countless hours and significant resources are lost because of poorly written code. But it doesnβt have to be that way.
There's a lot that goes into clean code, but the following bullets sum it up nicely:
Follow standard conventions.
Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
Boy scout rule. Leave the campground cleaner than you found it.
Always find root cause. Always look for the root cause of a problem.
The code should be the coding standard
and now....Your Daily Memes



What did you think about today's newsletter? |