PDI · Question #33
What is the result of the following code?
The correct answer is C. The record will not be created and no error will be reported.. The result of the code is that the record will not be created and no exception will be thrown, indicating a DML operation was performed using the allOrNone = false parameter which suppresses exceptions for individual record failures.
Question
What is the result of the following code?
Options
- AThe record will not be created and a exception will be thrown.
- BThe record will be created and a message will be in the debug log.
- CThe record will not be created and no error will be reported.
- DThe record will be created and no error will be reported.
How the community answered
(49 responses)- A6% (3)
- B2% (1)
- C90% (44)
- D2% (1)
Why each option
The result of the code is that the record will not be created and no exception will be thrown, indicating a DML operation was performed using the `allOrNone = false` parameter which suppresses exceptions for individual record failures.
An exception would be thrown if the DML operation was performed without the `allOrNone = false` parameter (e.g., standard DML `insert record;`) and a failure occurred.
If the record fails creation, it will not be created; while a message might appear in the debug log if an exception is caught and logged, the core outcome is non-creation due to failure.
When using `Database.insert(recordList, false)`, if a record fails validation or other database constraints, it will not be inserted, but the operation will continue for other records (if any), and no unhandled exception will be thrown, resulting in 'no error reported' to the caller.
The record will not be created if there's a DML failure; the outcome of 'record created' contradicts the scenario implied by 'no error reported' for a failing DML operation with `allOrNone=false`.
Concept tested: DML operations with partial success / error handling
Source: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_database_dml_options.htm
Topics
Community Discussion
No community discussion yet for this question.