I know there has been lot of things available online for record locking errors but I am putting my analysis based on client issue that we are facing, would appreciate if I can get any thoughts.
We have one visual-force page we name it as Survey Program Page and inside that we have table where in user can configure multiple criteria s by adding multiple rows as in say e.g
Row 1 - Account.Name = "xyz" Row 2 - Account.Email__c = "firstname.lastname@example.org"
We have process builder at backed on Account which has
@InvocableMethod which creates custom object record by taking AccountId.
There is also one Trigger on account which do some manipulation on Account record.
As per order of execution Trigger will execute first then Process builder.
Now, User creates Account record with
Account.Name = "xyz" &
Account.Email__c = "email@example.com"
First, Account Trigger will be executed and it will do its processing.
Second, Process builder will be executed,
@InvocableMethod will create custom object record by taking AccountId
We are receiving error
UNABLE TO LOCK ROW when
@InvocableMethod tries to create custom object record.
I believe Account Trigger will place lock first on Account Record.
A given transaction can only wait a maximum of 10 seconds for a lock to be released, otherwise it will time out.
I have following questions in my mind
Are we receiving error because Account trigger is taking longer than 10 sec to release lock before it passes Account Record to process builder
How does locking work internally ? does each process puts lock and every other process can wait maximum up to 10 sec before previous process release its lock, if its more than 10 sec then next process will throw error as
UNABLE TO LOCK ROWor
UNABLE TO OBTAIN EXCLUSIVE ACCESS OF THIS RECORD
If this is the case then what would be the ideal approach to deal with this scenario.
- Should we work on optimizing code for Account Trigger so that execution time/ locking period will reduce to less than 10 sec.
- Is there something that we can do inside process builder so that we can avoid record locking errors.