SF-PD2 Testing, Debugging, and Deployment Practice Question
A developer needs to debug an Apex trigger that intermittently fails in production with a 'UNABLE_TO_LOCK_ROW' error when multiple users update related records. Which technique should the developer use to capture the detailed execution context and identify the conflicting transaction?
⚠ Common exam trap
The trap here is assuming that query optimization tools or custom logging can reveal row lock conflicts, when only debug logs capture the necessary DML sequence and lock error details.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Enable debug logs for the triggering user and analyze the log for the row lock error and preceding DML operations.
Debug logs are the primary tool for diagnosing runtime errors like UNABLE_TO_LOCK_ROW. They record the exact DML operations and the order in which they occurred, including the records involved. By enabling a debug log for the affected user, the developer can see which DML statement failed to acquire a lock and what operations preceded it. This information is critical to identify the conflicting transaction and refactor the code to avoid locking contention.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Run the Apex Test Execution with 'Always Run Asynchronously' enabled to simulate concurrent updates.
Why it's wrong here
Apex tests run in a single transaction and do not simulate true concurrent user transactions. The 'Always Run Asynchronously' option only affects how tests are executed, not the concurrency model. It cannot reproduce production row lock conflicts because tests do not execute in parallel with other user transactions. This approach would not capture the real-world locking scenario.
- ✓
Enable debug logs for the triggering user and analyze the log for the row lock error and preceding DML operations.
Why this is correct
Debug logs capture the sequence of DML operations, SOQL queries, and exceptions. By setting a debug log for the user who encounters the error, the developer can see which records were locked and by which operation. The log will show the DML statement that caused the lock and the preceding operations, helping identify the conflicting transaction. This is the most direct way to diagnose row lock issues in production.
- ✗
Set up a custom logging object and insert a record at the start of each trigger invocation to track user activity.
Why it's wrong here
Custom logging can track trigger invocations, but it adds DML operations that can exacerbate row locking and governor limits. It also does not capture the platform-level lock information or the exact SQL error details. Debug logs provide a more comprehensive view without introducing additional DML that could change the behavior or cause recursive locks.
- ✗
Use the Developer Console's Query Plan tool to analyze the selectivity of the SOQL queries in the trigger.
Why it's wrong here
The Query Plan tool helps optimize query performance by showing selectivity and cost, but it does not diagnose row lock errors. Row locks occur during concurrent DML operations, not from query execution. While query performance can indirectly affect lock duration, the tool does not provide information about which transaction holds the lock or the DML sequence leading to the error.
About these practice questions
One of 226 original SF-PD2 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official Salesforce exam blueprint
This SF-PD2 practice question is part of Courseiva's free Salesforce certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the SF-PD2 exam.