Salesforce Platform Developer I (legacy) — Question 209
A developer is debugging the following code to determine why Accounts are not being created.
Account a = new Account(Name = 'A');
Database.insert(a, false);
How should the code be altered to help debug the issue?
Answer options
- A. Add a System.debug() statement before the insert method.
- B. Collect the insert method return value in a SaveResult record.
- C. Set the second insert method parameter to TRUE.
- D. Add a try/catch around the insert method.
Correct answer: B
Explanation
The correct answer is B because collecting the return value in a SaveResult record allows the developer to inspect any errors that occurred during the insert operation. Option A does not provide enough information, option C would change the behavior of the insert method, and option D could catch exceptions but would not give detailed information about the insert operation's success or failure.