An external system is pushing data into my org using bulk API. There are about 2 million records. The target object is child__c. The child__c has a lookup to parent__c. When the external system loads the data I get an error for some records saying: UNABLE_TO_LOCK_ROW:unable to obtain exclusive access to this record. I have found the root cause of this at this article - https://help.salesforce.com/articleView?id=000229525&type=1 .
Now I am looking for the solution to over come this problem. Following are three things I found:
- Reduce the batch size - Batch size is already 2000 for 2 million record. Will this help?
- Process the records in Serial mode instead of parallel, that way on batch is processed at a time. - Sure , serial mode will resolve this problem but what is the impact on the time to insert the records then. Given the size is 2 million. How long it might take if the batch size is 2000 records.
- Sort main records based on their parent record, to avoid having different child records (with the same parent) in different batches when using parallel mode.- This does not seem to suit my solution since the external system have to make changes to the code.
Appreciate any suggestion from the community?
child__c.parent__c
you should be fine (depending on the amount of dependent records).