nerdexam
Salesforce

PDI · Question #169

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…

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

How the community answered

(47 responses)
  • A
    6% (3)
  • B
    2% (1)
  • C
    2% (1)
  • D
    89% (42)

Why each option

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.

AAdd a System.debug() statement before the insert method

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.

BAdd a try/catch around the insert method

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.

CSet the second insert method parameter to TRUE

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.

DCollect the insert method return value a Saveresult variableCorrect

When the `allOrNone` parameter of `Database.insert()` is set to `false`, the operation does not throw exceptions upon failure; instead, it returns a `Database.SaveResult` object containing success/failure information and specific errors, which must be collected and examined for debugging.

Concept tested: Database DML Error Handling

Source: 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 Practice