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](https://www.mstsolutions.com/wp-content/uploads/2020/12/image-981.png)
Hyperbatch class:
Deleting contacts: traditional batch class vs HyperBatch
Time taken to delete 1739 contacts.
Traditional batch:
![hyperbatch](https://www.mstsolutions.com/wp-content/uploads/2020/12/image-980.png)
Hyperbatch:
![hyperbatch](https://www.mstsolutions.com/wp-content/uploads/2020/12/image-982.png)
Updating accounts: batch class vs HyperBatch.
Time taken to update 22 accounts.
Traditional batch class:
![hyperbatch](https://www.mstsolutions.com/wp-content/uploads/2020/12/image-983.png)
HyperBatch:
![hyperbatch](https://www.mstsolutions.com/wp-content/uploads/2020/12/image-984.png)
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: