I’ve written a zap that does the following:
- Starts when a new csv file is found in an amazon s-3 bucket. The file contains a list of donations, one per line, for which I need to create opportunities in Salesforce.
- Loops through each line in the csv file. For each line
- Does a lookup to find a matching account. It splits on whether or not there is a match
- If there is a match, it creates a new opportunity for the account. This works fine.
- If there is not a match, I am creating an opportunity in a generic account called Lighthouse. This fails randomly.
The problem is with step 2.3. For example, my csv file has 10 detail lines. 8 of the lines do not have a matching account, so it tries to create 8 opportunities in step 2.3, all on the same related account (Lighthouse). That should be fine, but I am seeing this error in Zapier, which is coming from Salesforce:
“Could not create record of the "Opportunity" object: unable to obtain exclusive access to this record or 1 records: <record id>”
The <record id> is the generic Lighthouse account. My theory is Zapier is trying to run in parallel, meaning it is trying to create 2 or more opportunities at the same time on the generic Lighthouse account. When an Opportunity is created in Salesforce, it temporarily locks the associated Account record. Trying to create 2 opportunities at the same time on the same account would cause this kind of error.
Is there a way to force Zapier to run in serialized mode (like you can in Data Loader), or do you have any other ideas on how to prevent this record locking conflict? Or maybe other theories as to what is causing the error?
Best answer by mzsadiekView original
@Edify! Have you tried to create a delay before creating the opportunity? It doesn’t have to be a delay of 1 minute, as this article from Troy explains: