Order of execution in Row lock seen in Master-Detail relationship
|Knowledge Article Number||000231947|
|Description||What is Order of execution in case of Row lock where Master record is locked?|
1. Object A - Object B have master detail relationship A being the Master and B the detail
2. Record A is locked in a Transaction
3. Record B starts a new DML operation.
4. This is when the system loads the original Record B from the database or initializes the record for an upsert or insert statement.
Steps from 1-15 are executed for record B mentioned in Order of execution
At step 16, Internally system checks if it can place lock on the Parent Record A ; but because Record A is already locked, we cannot place another lock.
5. Record B waits for a maximum of 10 seconds for system to obtain lock over Record A
6. a. If lock on Record A is released within the 10 seconds, system gets to place lock on Record A and proceed with steps 1 for Record A.
6. b. If Record A process is still underway beyond 10 seconds, User sees the row lock error. At this point the DML operation is rolled back to the previous savepoint (Previous state before the record update/Insert). As the lock is exclusively not obtained on Record A, steps 1-15 in Order of execution are not executed for Record A
There's overview of various scenarios when Row lock errors are seen.