Intro to DML
Reading Only

DML stands for Data Manipulation Language. It's used in Apex to create, update, restore, and delete sObject records from the database. This is not the same as SOQL.

SOQLvApex



DML Operations can be performed using Apex DML statements or by using the methods of the Database class. For this course, we'll cover DML statements. In the next, we'll cover the Database class.

DML Statements

DML Statements are simple and straightforward ways to insert, update, merge, delete, and undelete sObjects records from the database. This really opens up what's possible with Apex. Whether the DML is in a Trigger or being called from a LWC, our Apex code now has the ability to alter the database.

There are just 2 parts to a DML statement. The first part declares the DML operation type. The second defines what sObjects should undergo the DML operation.

operationType sobjectRecords;

Say you had a list of Account records you wanted to insert, you'd do so with:

insert accountRecordList;

Or if you wanted to update a single Case:

update singleCaseRecord;

We'll show you how each of these work. Here are a couple things to keep in mind before we go further.

Governor Limits

DMLs are directly subject to two Governor Limits.

Only 150 DML statements can be issued in a transaction. Only 10,000 records can be processed as a result of DML statements. We'll explore these limits.

Exceptions

Sometimes DML statements fail. Whether it fails because of Validation Rules or an array of other issues - DML statements are not guaranteed to succeed. When DML statements fail, they throw exceptions. We'll also learn how to handle these too.