Salesforce Platform Record Locking and Concurrency

The Salesforce platform uses locks to ensure referential data integrity. When dealing with large data volumes, record locks and contention can impact performance. We've created a cheat sheet with details of the most common locking issues.

Force.com Record Locking Cheatsheet

Similar to any application built on a relational database, Salesforce uses locks to ensure referential integrity of its data. Most transactional database operations only hold these locks for a very short period of time and the volume is not significant enough to cause contention. However, for some operations, record locks and contention can become an architect’s nightmare.

For operations that involve manipulating data records, running multiple processes that affect the same object or collection of objects risks record locking errors and should be avoided if possible. Record locking contention is also possible within a single process if updates are being processed multi-threaded, especially when dealing with child objects where multiple records may look up to the same parent.

Similarly, operations that make changes to the role hierarchy, territory hierarchy or group member assignments require an organization wide group membership lock. Group member assignments include all types of groups including public and private groups, roles, territories and queues. When a group membership operation is being performed, other group membership operations will be unable to obtain the group membership lock. As a result, most group maintenance updates must run in serial to reduce the risk of lock exceptions.

There are other operations that can result in locking contention. To help you understand what causes some of the most common locking issues, we’ve created a new Record Locking cheat sheet.

In this cheat sheet, locking behavior is organized into three categories: object-specific locking behavior, custom configuration locking behavior, and sharing locking behavior. The information in this cheat sheet is additive, so to use this cheat sheet, look for all rows that might apply to your scenario. For example, if you are performing an insert of an opportunity record and you have a roll-up summary field on the account object, and a lookup to a custom object, you would need to look at the following three rows:

  1. In Object-Specific Locking Behavior, the Opportunity row indicates that the parent Account will be locked on an insert.
  2. In Custom-Configuration Locking Behavior, the “Record with a roll-up summary field” row indicates the master record (in this case, the account again) will be locked on an insert.
  3. Also in Custom-Configuration Locking Behavior, the “Record with a lookup relationship” row indicates the lookup record (in this case, the custom object) will be locked on an insert.

You can also find detailed information about record and group locking in the documents referenced below, and many others on the Architect Core Resources page on the Salesforce Developers site.

Related Resources

About the Author

Dan Yu is a Technical Writer within the Technical Enablement team of the salesforce.com Customer-Centric Engineering group. The team’s mission is to help customers understand how to implement technically sound Salesforce solutions. Check out all of the resources that this team maintains on the Architect Core Resources page of Developer Force.

Leave your comments...

Salesforce Platform Record Locking and Concurrency