Salesforce Dictionary - Free Salesforce GlossarySalesforce Dictionary
Salesforce Developer
easy

What is DML in Apex and what are its limits?

DML (Data Manipulation Language) is how Apex inserts, updates, deletes, undeletes, and upserts records. Two syntaxes:

Statement form (concise):

apex insert acc; update accList; delete oppList; upsert leads External_Id__c;

Database method form (more options):

apex Database.SaveResult[] results = Database.insert(accList, false); // false = allow partial success

Database methods give you partial-success flag (allOrNone = false) and per-record SaveResult objects with success/error info.

Governor limits:

  • 150 DML statements per transaction.
  • 10,000 records per DML in sync; higher async.
  • Each statement counts as one regardless of record count.

Best practices:

  • Bulkify: do one insert listOfX instead of insert x in a loop. Loops with DML inside hit the 150 limit fast.
  • Don't mix sObject types in one Database method call — that's a different limit.
  • Use upsert with External Id for integrations to avoid duplicate-key issues.

DML inside a loop is the #1 anti-pattern in Apex.

Why this answer works

Foundational. The "DML inside a loop" anti-pattern is the most common entry-level mistake. Showing both syntax forms signals real coding experience.

Follow-ups to expect

Related dictionary terms