PDI · Question #229
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?
The correct answer is A. Database.insert (records, false). The question seeks the DML statement that allows some records in a list to be inserted successfully even if others fail, known as partial success.
Question
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?
Options
- ADatabase.insert (records, false)
- Binsert records
- Cinsert (records, false)
- DDatabase.insert (records, true)
How the community answered
(21 responses)- A95% (20)
- C5% (1)
Why each option
The question seeks the DML statement that allows some records in a list to be inserted successfully even if others fail, known as partial success.
The `Database.insert(records, false)` method allows for partial success, meaning that if some records fail to insert, the successful records will still be committed to the database without rolling back the entire transaction.
The shorthand `insert records` statement operates in 'all or nothing' mode by default, so if any record fails, the entire transaction is rolled back.
`insert (records, false)` is not a valid Apex DML syntax for controlling partial success.
`Database.insert(records, true)` explicitly enforces 'all or nothing' behavior, meaning the entire transaction will roll back if any record fails.
Concept tested: Partial success DML operations
Source: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_database.htm#apex_System_Database_insert_2
Topics
Community Discussion
No community discussion yet for this question.