How to handle locking exception?

When an sObject record is locked, no other client or user is allowed to make updates either through code or the Salesforce user interface. The client locking the records can perform logic on the records and make updates with the guarantee that the locked records won’t be changed by another client during the lock period.

Apex has the possibility of deadlocks, as does any other procedural logic language involving updates to multiple database tables or rows.

To avoid such deadlocks, the Apex runtime engine:

1. First locks sObject parent records, then children.

2. Locks sObject records in order of ID when multiple records of the same type are being edited.

As a developer, use care when locking rows to ensure that you are not introducing deadlocks. Verify that you are using standard deadlock avoidance techniques by accessing tables and rows in the same order from all locations in an application.

No comments:

Post a Comment