Salesforce Certified Platform Developer II — Question 189
An Apex trigger creates an Order__c record every time an Opportunity is won by a Sales Rep. Recently the trigger is creating two orders.
What is the optimal method for a developer to troubleshoot this?
Answer options
- A. Set up debug logging for every Sales Rep, then monitor the logs for errors and exceptions.
- B. Turn off all Workflow Rules, then turn them on one at time to see which one causes the error.
- C. Add system.debug() statements to the code and use the Developer Console logs to trace the code.
- D. Run the Apex Test Classes for the Apex trigger to ensure the code still has sufficient code coverage.
Correct answer: C
Explanation
The correct answer is C because adding system.debug() statements allows the developer to trace the execution flow and identify where the duplicate Order__c records are being created. Option A, while helpful, does not directly address the code execution itself, and option B may not be relevant if the issue lies in the trigger logic rather than Workflow Rules. Option D checks code coverage but does not provide insights into runtime behavior or logic errors.