Refer to the exhibit. A batch process updating 50,000 records frequently fails with the error shown. Which design change resolves this contention?
Exhibit
Error: UNABLE_TO_LOCK_ROW: unable to obtain exclusive access to this record
Trap 1: Implement a retry mechanism using a custom setting.
A retry mechanism is a reactive workaround rather than an architectural solution. While it might mask the issue, it does not fix the root cause of lock contention. The process will still experience performance degradation and potential failures, and it does not improve the system's throughput efficiency.
Trap 2: Change the batch size to 1.
Processing records one by one with a batch size of one will significantly increase the total processing time, potentially causing the overall job to exceed the maximum execution time. While it reduces contention, it is an extremely inefficient way to handle large volumes of data in Salesforce.
Trap 3: Disable all sharing rules on the object.
Sharing rules are calculated during record updates to maintain data access integrity. Disabling them is generally not possible in production and would violate security requirements. Even if disabled, row locking is a database-level mechanism designed to maintain data integrity, which would still apply to object updates.
- A
Implement a retry mechanism using a custom setting.
Why it fails: A retry mechanism is a reactive workaround rather than an architectural solution. While it might mask the issue, it does not fix the root cause of lock contention. The process will still experience performance degradation and potential failures, and it does not improve the system's throughput efficiency.
- B
Group records by parent ID before processing.
Grouping records by parent ID ensures that all child records associated with a specific parent are processed together. This prevents multiple concurrent batch threads from requesting locks on the same parent record simultaneously, which is the primary cause of row locking errors in complex data structures.
- C
Change the batch size to 1.
Why it fails: Processing records one by one with a batch size of one will significantly increase the total processing time, potentially causing the overall job to exceed the maximum execution time. While it reduces contention, it is an extremely inefficient way to handle large volumes of data in Salesforce.
- D
Disable all sharing rules on the object.
Why it fails: Sharing rules are calculated during record updates to maintain data access integrity. Disabling them is generally not possible in production and would violate security requirements. Even if disabled, row locking is a database-level mechanism designed to maintain data integrity, which would still apply to object updates.