1

I am uploading about 800 records into salesforce using the salesforce inspector extension with the data import option. enter image description here

Per normal bulkification standards, the batches run in increments of 200 records at a time, and I have set to use 6 threads at a time. However, I am getting a lot of locking errors on my records, and this is because I am trying to create all of these records as the child of the same parent record.

I have some some research and found out that when a child record is updating (after inserting, I have an extensive flow and some custom apex running on the records to update certain pieces), it will put a lock on the parent as well. As a result, if a sibling record in a different batch attempts to update, it will experience a lock error because it was unable to put the necessary lock on the parent record.

For the most part, this makes sense to me. However, there are a couple things I don't understand. First, why do I not experience lock records with batches? For example, if every one of the records I am uploading required lock access to the SAME parent record, then I would expect some sort of problems within the individual batches of 200 records. However, when I run the process with a single thread, all the batches process fine. So, it appears that these lock errors only apply across batches, and not within batches? Is this a correct understanding, and if so, why does this locking error not happen within a single batch when all the records (200) are trying to access a single parent record?

Also, it seems odd to me that this functionality exists from the perspective of attempting to upload a large group of data all to a single parent record (for example, I have a List object which is the parent, and I want to upload all the List Entries at once, which are all children of the same List record). It seems like this would be a pretty common use case, so is there some better method of accomplishing this than what I am trying?

1 Answer 1

3

Record locks occur at the transaction level. That means that all records in a 200-record-sized chunk can share the lock, but other concurrent processes cannot. This is why you can upload a large number of records in serial to the same parent, but not in parallel. You should set up your jobs in a way where each parent appears in no more than one batch at a time to reduce row-lock errors.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .