HyperBatch for Salesforce

Share on facebook
Share on twitter
Share on linkedin
Field service management is helpful in numerous industries for mobile workers or contractors. Usages includes public utilities and transportation, vending machine services, telecommunications, waste management, in-home health and child care, financial services, retail, professional services, and manufacturing.

Introduction: 

HyperBatch is a tool used to process large amount of records. It is an alternative to batch classes in Salesforce. Using this tool, we can perform all DML operations which can be accomplished by batch classes. The Hyperbatch gives a significant performance improvement compare to batch classes, but it needs to run from an UI and can’t be scheduled to run.

Scenario: 

Suppose we have a requirement to create three contact records for 150k Account records.

What are the ways to meet the above requirement?

The first solution is using a Batch class in Salesforce.

Drawbacks of batch class:

Here, we cannot perform the operation on synchronization mode.

Batch class takes longer time to process the number of records compared to Hyperbatch.

Retry logic can be built when there is a failure, but it will likely exceed the transaction limits.

Efficient way to do the above process: 

The above drawbacks can be overcome by HyperBatch.

 Hyperbatch Traditional Batch
User interfaceYes (required)No
SchedulableNoYes
Invoking another BatchNoYes
AsynchronousYes (5 running per organization)Yes (Not subject to 50 job per transaction limit (each request can be considered as a new transaction))
SynchronousYesNo
Row lock behaviorRow locks retry automatically until the transaction succeeds. Each re-attempt gets a new context Default is a failed batch execution. Retry logic can be built, but it will likely exceed the transaction limits. 

Creating Contacts: Traditional batch class vs Hyperbatch

Time taken to crate 1166 contacts.

Traditional batch class: 

hyperbatch

 Hyperbatch class: 

hyperbatchDeleting contacts: traditional batch class vs HyperBatch

Time taken to delete 1739 contacts.

Traditional batch: 

hyperbatch

Hyperbatch: 

hyperbatch

Updating accounts: batch class vs HyperBatch.

Time taken to update 22 accounts.

Traditional batch class: 

hyperbatch

HyperBatch: 

hyperbatch
OperationDatabase.batchable (in seconds)Hyperbatch(in seconds)Difference(in seconds)
Create contact16106
Delete contact1798
Update account211

How does HyperBatch work?

  • HyperBatch interface can work like how Database.Batchableinterface does.
  • Browser perfectly works on selecting jobs as well as running them on-demand.
  • AJAX toolkit for PK chunking the query locator.
  • Each execute can return some state of type Object, it can be anything.

Asynchronous: 

  • Parallel remote actions call the queueables for the batch executions methods. (Not serial!)
  • JavaScript polls for the status of the queueables, waiting for them to complete.
  • Execute state is stored in a custom object, and a list of them is returned to the finish() method, then they are deleted.

Synchronous: 

  • Parallel remote actions fire the synchronous transactions. (Not serial!)
  • Execute state is returned synchronously and stored in JavaScript in the browser until they are all complete.

Hyperbatch Resources: 

https://developer.salesforce.com/blogs/developer-relations/2015/11/pk-chunking-techniques-massive-orgs.html
https://developer.salesforce.com/blogs/developer-relations/2016/11/french-touch-dreamin-first-community-led-event-france.html
https://github.com/danieljpeter/HyperBatch

About MST

At MST Solutions our cornerstone is to adapt, engage and create solutions which guarantee the success of our clients. The talent of our team and experiences in varied business verticals gives us an advantage over other competitors.

Recent Articles

Sandbox Overview

Salesforce allows you to create multiple copies of your production organization in separate environments for different purposes, like testing, development and training, without affecting data and applications of production instance. These copies are called Sandboxes.

Read Article »

Work with us.

Our people aren’t just employees, they are key to the success of our business. We recognize the strengths of each individual and allow them time and resources to further develop those skills, crafting a culture of leaders who are passionate about where they are going within our organization.