Salesforce - Developer - DML

salesforce-developer

https://trailhead.salesforce.com/apex_database/apex_database_dml

Unlike DML statements, Database methods have an optional allOrNone parameter 
that allows you to specify whether the operation should partially succeed. When 
this parameter is set to false, if errors occur on a partial set of records, 
the successful records will be committed and errors will be returned for the 
failed records. Also, no exceptions are thrown with the partial success option.

This is how you call the insert method with the allOrNone set to false.

Database.insert(recordList, false);
Database.SaveResult[] results = Database.insert(recordList, false);

Upsert returns Database.UpsertResult objects, and delete returns 
Database.DeleteResult objects.

By default, the allOrNone parameter is true, which means that the Database 
method behaves like its DML statement counterpart and will throw an exception 
if a failure is encountered.

DML operations execute within a transaction. All DML operations in a transaction 
either complete successfully, or if an error occurs in one operation, the entire 
transaction is rolled back and no data is committed to the database. The 
boundary of a transaction can be a trigger, a class method, an anonymous block 
of code, an Apex page, or a custom Web service method. For example, if a trigger 
or class creates two accounts and updates one contact, and the contact update 
fails because of a validation rule failure, the entire transaction rolls back 
and none of the accounts are persisted in Salesforce.
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License