Data Manipulation Language (DML) in Salesforce Apex – Complete Guide with Examples

In Salesforce, to retrieve the data from the Salesforce org, we use a SOQL query. However, when performing data operations (such as Insert, Update, and Delete) on Salesforce records, we use DML (Data Manipulation Language) in Salesforce Apex.

Working with data is one of the most important tasks. Every business application needs to create, update, or delete records in the database.

In Salesforce, we use Data Manipulation Language (DML) in Apex to perform these operations. DML allows developers to interact with the Salesforce database and manage records efficiently.

If you are learning Apex, understanding DML is very important because it is used in almost every real-time project.

Whether you are building automation, writing triggers, or developing integrations, you will use DML operations. Apex is a powerful programming language that runs on the Salesforce platform and enables developers to build business logic directly in the database.

In this tutorial, we will learn about Data Manipulation Language (DML) in Salesforce Apex. Additionally, I will explain the DML operations that can be performed and how to execute them within Apex classes.

What is Data Manipulation Language (DML) in Salesforce Apex?

DML stands for Data Manipulation Language, which performs operations on records, such as inserting new records, updating existing records, deleting records, and restoring deleted records. It helps developers manage data inside the Salesforce database.

DML is used to update data in Salesforce. For example, when a user creates a new account, updates a contact, or deletes a record, DML operations are executed behind the scenes.

These operations can be performed on a single record or multiple records at once.

DML allows us to perform operations on a single sObject record or in bulk on a list of records simultaneously. DML is a very important part of Apex for updating Salesforce databases.

DML operations are very fast and efficient because they are optimized for the Salesforce multi-tenant environment. This means multiple users and organizations can use the same platform without affecting performance.

Why Do We Use DML in Apex?

DML is used whenever we need to modify data in Sales