Lead Applications Engineer, Kenandy
Bay Area Salesforce Developer User Group Organizer
A Hyper-Fast Batchable Interface for Salesforce
Case study: Account / Contact Batches
• Prerequisite: 121K Accounts already in the system
• CreateContactsBatch: Creates 3 Contacts for each Account with a random
“probability” field for each. 363k Contacts total.
• UpdateAccountsBatch: For each Account, update the highest and lowest
probability on the Account by querying the child Contacts. Get the overall
highest and lowest probability across all the Accounts.
• DeleteContactsBatch: Delete all of the Contacts in the system. Keep a running
total of how many get deleted.
• Using traditional Apex Database.Batchable: 45 mins
• Using traditional Apex Database.Batchable: 10 mins
• Using traditional Apex Database.Batchable: 33 mins total (got row lock errors,
had to run twice)
• Using HyperBatch
• 2 mins 12 seconds
Row lock behavior
• Apex Batch: default is a failed batch execution. Retry logic can be built, but it
will likely exceed the transaction limits.
• HyperBatch: row locks retry automatically until the transaction succeeds. Each
re-attempt gets a new context!
How it Works
• HyperBatch interface that mimics the Database.Batchable interface.
• Browser orchestration for selecting jobs and running them on-demand.
• Lightning Design System, Visualforce (Lightning Components would be a data bottleneck).
• AJAX toolkit for PK chunking the query locator.
• Each execute can return some state of type Object, it can be anything.
• Parallel remote actions fire the qeueables for the batch executions methods. (Not serial!)
• Execute state is stored in a custom object, and a list of them is returned to the finish() method,
then they are deleted.
• Parallel remote actions fire the synchronous transactions. (Not serial!)
• Synchronous mode
• Batch Size Control
• Test Methods
• Throttle requests (x number of open connections)
• Enhance the user interface
• Support custom iterators instead of just query locator
• Support simple data operations like update a field or delete records
without having to write Apex
• Chunk in 2 dimensions: (Parent Id, then Record Id) to avoid row
• Salesforce Developer Blogs
• “Data Chunking Techniques for Massive Orgs“ by Daniel Peter
• “French Touch Dreamin’ – The first community-led event in France” by Philippe Ozil
• Presentation from Forcelandia 2016: “PK Chunking – Divide and conquer massive objects
in Salesforce” (http://www.slideshare.net/danieljpeter/forcelandia-2016-pk-chunking)
• GitHub repo: HyperBatch (https://github.com/danieljpeter/HyperBatch)