DEV Community


DML in Apex

bhanukarkra profile image bhanukarkra ・1 min read
insert, update, upsert, delete, undelete, merge

Each DML statement accepts either a single sObject or a list (or array) of sObjects (more efficient.)

The merge statement merges up to three records of the same sObject type into one of the records, deleting the others, and re-parenting any related records.

compares value of one field (user defined) or ID to check for insertion or update.

*If the key is not matched, a new object record is created.
*If the key is matched once, the existing object record is updated.
*If the key is matched multiple times, an error is generated and the object record is neither inserted or updated

Database methods (built in)
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.

Database.insert(recordList, false); //allornone set to false.
Default is true.

Discussion (0)

Editor guide