How can I avoid record lock error on accounts?
You might get a record lock error on accounts or contacts when you try to update it.
This happens because:
- There are parallel updates to the same record by another service request or UI.
- You're creating or updating relationship records for a contact in a batch pointing to same account record.
- You're creating or updating relationship records for an account in a batch pointing to same contact record.
When you create a new account or contact relationship, then the parent record gets updated along with the child record. This causes a record lock error on the parent. This happens more so when there is parallel record create or update using web services.
To avoid this issue, consider the following:
- When creating or updating relationships for a contact in a batch operation the same Account shouldn’t be used.
- When creating or updating relationships for Accounts in a batch operation the same contact shouldn’t be used.
- Parallel updates should be avoided to the same account or contact record by Service or UI flows.
To avoid Locks in such cases it’s recommended to have a Retry mechanism in place.