nerdexam
SalesforceSalesforce

PDI · Question #169

PDI Question #169: Real Exam Question with Answer & Explanation

The correct answer is D: Collect the insert method return value a Saveresult variable. When using Database.insert() with allOrNone set to false, exceptions are suppressed, and the method returns a SaveResult object that must be inspected to determine success or failure and retrieve error details.

Submitted by weili_xi· Apr 18, 2026Logic and Process Automation

Question

A developer is debugging the following code to determinate 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?

Options

  • AAdd a System.debug() statement before the insert method
  • BAdd a try/catch around the insert method
  • CSet the second insert method parameter to TRUE
  • DCollect the insert method return value a Saveresult variable

Explanation

When using Database.insert() with allOrNone set to false, exceptions are suppressed, and the method returns a SaveResult object that must be inspected to determine success or failure and retrieve error details.

Common mistakes.

  • A. Adding a System.debug() before the insert method would only display the record's state prior to the operation, not the actual outcome or any errors that occurred during the insert.
  • B. A try/catch block will not catch exceptions when allOrNone is false because Database.insert() suppresses exceptions and returns error information in the SaveResult object instead.
  • C. Changing the allOrNone parameter to true would alter the method's behavior to throw an exception on failure, which changes the original debugging scenario where exceptions are suppressed.

Concept tested. Database DML Error Handling

Reference. https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_database_dml.htm

Topics

#Apex DML#Error Handling#SaveResult#Debugging Apex

Community Discussion

No community discussion yet for this question.

Full PDI PracticeBrowse All PDI Questions