You are using an older browser that might negatively affect how this site is displayed. Please update to a modern browser to have a better experience. Sorry for the inconvenience!

HyperBatch for Salesforce


By: Radha

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 interface Yes (required) No
Schedulable No Yes
Invoking another Batch No Yes
Asynchronous Yes (5 running per organization) Yes (Not subject to 50 job per transaction limit (each request can be considered as a new transaction))
Synchronous Yes No
Row lock behavior Row 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 class: 

Deleting contacts: traditional batch class vs HyperBatch

Time taken to delete 1739 contacts.

Traditional batch: 

Hyperbatch: 

Updating accounts: batch class vs HyperBatch.

Time taken to update 22 accounts.

Traditional batch class: 

HyperBatch: 

Operation Database.batchable (in seconds) Hyperbatch

(in seconds)

Difference

(in seconds)

Create contact 16 10 6
Delete contact 17 9 8
Update account 2 1 1

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