Salesforce Platform Developer I (legacy) — Question 62

An Apex transaction inserts 100 Account records and 2,000 Contact records before encountering a DML exception when attempting to insert 500 Opportunity records.
The Account records are inserted by calling the database.insert() method with the allOrNone argument set to false. The Contact and Opportunity records are inserted using the standalone insert statement.
How many total records will be committed to the database in this transaction?

Answer options

Correct answer: C

Explanation

In this scenario, because the Opportunity record insertion fails, the entire transaction is rolled back due to the use of standalone insert statements for Contacts and Opportunities. Even though the Account records were inserted with allOrNone set to false, the failure of any operation in the transaction leads to no records being committed, resulting in a total of 0 records saved.