1

I'm currently using the Salesforce Bulk API within a Rails app to update a custom object in Salesforce. This works fine when I send a single record through, but when I batch in sets of 200, I get many UNABLE TO LOCK ROW errors.

Is there a way to tell the Bulk API to process only one batch at a time? It seems like the processes are running in parallel if there are more than 200 rows to update.

Currently using this gem with Rails: https://github.com/yatish27/salesforce_bulk_api

4

This error is not about the batchsize which you are thinking of.

This is occurring in the parallel mode when API tries to lock the parent record or any record in the relationship at the time of updating the child record.

Let's say, you are trying to update Contact record through Bulk API and during update it will try to lock the Parent Account record and if the lock is not released from other threads you will face Unable to lock a row error.

Solution

Prepare the data set ordering by the Parent record and ordering by related Lookup fields.

The Parent record should not have more than 10000 children otherwise it will be parent data skew.

If you still face the same issue considering those 2 points then use Bulk API with serial mode option.

0

Edit: As noted, this won't solve the underlying issue and will likely make it worse.


The Bulk API definitely has a way to control the batch size. I'm not familiar with this library but I just took a quick look at the code and it appears that you can pass in the batch size as an option. For example, here's the signature for the create method:

create(sobject, records, get_response = false, send_nulls = false, batch_size = 10000, timeout = 1500)

   So it seems that you can call the API methods and pass in a batch size of 200.

  • 3
    That is more likely to exacerbate the problem. The Bulk API batch size isn't the same as a transaction batch size; instead, each batch contains up to 10,000 records that will be processed 200 at a time, but each batch may be processed in parallel. Splitting batches in to groups of 200 will quickly exhaust the API limits and increase database contention. In other words, setting batch size = 200 is bad, but setting batch size of 10000 is good. – sfdcfox Oct 6 '18 at 6:47
  • You're right, I hadn't considered that. I updated the answer to clarify that it won't actually help. Thanks. – John Towers Oct 6 '18 at 10:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.