CRT-450 practice question 18 of 30

Which statement should be used to allow some of the records in a list of records to be inserted if others fail to be inserted?

Full set: 201 questions
Answer options
A: Database. insert (records, true)
B: insert records
C: insert (records, false)
D: Database. insert (records, false) Correct answer
Correct Answer:
D. Database. insert (records, false)
Explanation

The Database.insert() method provides an optional boolean parameter, allOrNone. When this parameter is set to false, the DML operation allows for partial success. This means if one record in the list fails to be inserted due to validation rules or other errors, the remaining valid records in the list will still be committed to the database. The method returns an array of Database.SaveResult objects, which can be inspected to identify which records succeeded and which failed, along with the reasons for failure.

References

1. Salesforce Apex Developer Guide: In the "Database Class Methods" section

it states

"The Database methods are static and are called on the class name. ... The optional allOrNone parameter specifies whether the operation can partially succeed. If you specify false for this parameter and a record fails

the remainder of the DML operation can still succeed."

Reference: Salesforce Developers

Apex Developer Guide

"DML Statements vs. Database Class Methods".

2. Salesforce Apex Developer Guide: The guide further clarifies the behavior of the allOrNone parameter for Database.insert: "The optional allOrNone parameter is available only for Database methods

not DML statements. This parameter specifies whether to allow partial success of the DML operation. If it’s set to false

and if a record in the list fails

the successful records are still committed...".

Reference: Salesforce Developers

Apex Developer Guide

"Performing DML Operations".

Scroll to Top