Asynchronous Apex

Episode 7 – Asynchronous Processing in Apex

Apex, Apex Hours for Students

Writing business logic in Apex that runs for a long duration is often a key ask by customers. In this episode we will learn about writing asynchronous process in Apex using Apex. Join us as you embark on this wonderful journey to become a champion Salesforce developer.

Episode 7 will be presented by Jigar Shah on Feb 18, 2020 at 6 PM Indian Standard Time.


  • Avenues of writing asynchronous processes
  • Batch Processing
  • Writing Scheduled Cron Jobs
  • Future Methods
  • Queueable
  • Q & A

Most importantly don’t break a leg if you are overwhelmed with the pace of the live sessions. All Apex Hours for Student sessions will be recorded and will be available on our YouTube channel.

Please register here and follow our ApexHours website to get more notification.

Here is some keynote from our session

Demystifying Asynchronous Processing

Demystifying Asynchronous Processing

Demystifying Asynchronous Processing

Understanding Batch Apex

Understanding Batch Apex

Anatomy of a Batch Job

Demo 1 – Batch Job

global class BatchDemo1 implements Database.Batchable<Sobject>{

	private Integer magicNum = 0;

	global Database.QueryLocator start(Database.BatchableContext bc){
		return Database.getQueryLocator('Select Id, Name From Account');
	global void execute(Database.BatchableContext bc, List<Account> scope){
		System.debug('In the execute method');
        for(Integer i = 0; i < 5; i++){
        	magicNum = i; 

	global void finish(Database.BatchableContext bc){
		System.debug('In the finish method');
		System.debug('magicNum ' + magicNum);

BatchDemo1 bd = new BatchDemo1();

Maintaining State in Batches .

Maintaining State in Batche

Considerations for Batch Apex

  • 50 million records can be processed
  • Use Batch Apex when there are more than 1 batches to be processed else opt for Queueable Apex
  • Fine tune your SOQL query to minimize QueryLocator records
  • Invocation from Triggers may lead to uncontrolled executions
  • Implement Database.AllowsCallouts to make Webservice calls

Understanding Scheduled Apex

Understanding Scheduled Apex

Crone job

Considerations for Schedulers

  • Maximum 100 jobs can be scheduled concurrently
  • Limit on maximum number of Scheduled Apex invocations on a per 24 hour basis
  • Synchronous Web service callouts are not supported from Scheduled Apex

Future Calls

  • Asynchronous jobs running in a separate thread when resources are available
  • @future annotation
  • Primitive type support only
  • Applicability
    • Callouts to external applications or webservices
    • Perform complex calculations
    • Resolve and Mixed DML Operation error

Key Future Method Considerations

Must be static and do not return anything other than void
Order of invocation is not respected
Primitive type support only
Cannot invoke a future method from another future method

Queueable Apex

  • Asynchronous process that can be queued for sequential processing
  • System.Queueable
  • Supports Primitive & Non-Primitive types as well
  • Generally used for Job Chaining

Which async artefact to use?

Need Batch Apex Scheduled Apex Future Methods Queueable Apex
Process large data volumes Yes
Execute logic at specific time intervals Yes
Perform Web Service Calls Yes Yes Yes
Sequential Processing (Chaining) Yes
Support for Non-Primitive (sObject, custom Apex types) Yes Yes Yes


Asynchronous Apex using future method and Queueable Apex

Further Learning

  • Async Apex Basics


Complete below assignment to win $1000 Salesforce Voucher. Click here for rule.

Write  a batch job that runs daily at 9 PM Local Time and searches for the newly created Accounts. The job then sums the Amount field value on every Opportunity for all the Opportunities and updates it on the respective Pipeline Amount field on the respective Parent Account record of those Opportunity.

(Hint: Assume Pipeline Amount field to be a custom currency field created on Account. Use a combination of Scheduled and Batch Jobs to achieve the desired functionality.)

Don’t forget to register for our next session on Integration in Salesforce. Check this post for all other session detail.

Please note that we have limit of 500 attendees that can join the online sessions. However, recording will be posted on our YouTube channel. Make sure to subscribe our YouTube channel to get notification for video upload.

So, learn at your pace and free will and ace your journey to Salesforce!

1,103 total views, 37 views today


Leave a Reply