Cut to the chase: What causes UNABLE_TO_LOCK_ROW errors and what are best practices for avoiding them?
We built a great app that works solidly in development and testing. Today we launched to a team of 80 people who were all using the app and submitting forms simultaneously... and started getting UNABLE_TO_LOCK_ROW errors right and left. I realize that it's hard to diagnose what's going wrong without looking at our code, but it's a mammoth project. Each person was submitting new, original data -- they weren't working on or accessing the same records at the same time. What else could be going on?
Some additional context to help with this:
- The save routine saves a new Contact record, followed by a bunch of related information in other records. According to debug logs, the
UNABLE_TO_LOCK_ROWerror always hits during the very first DML operation - the Contact insert.
- All of the Contacts are on the same Account. There are ~5000 Contacts on this Account; we've verified that there are no triggers or cross-object workflows affecting the Account.
- In the debug logs, the DML error hits immediately after exiting the last
before inserttrigger on the Contact record, which is in a managed namespace (but we've gotten the managed code and reviewed it, and it appears to be no-op for the records we're inserting).
- In successful saves, the next lines in the debug logs are for validation rules.