Too many DML statements 151.
DML inside a loop hits 151 statements. The trigger crashes mid-transaction — partial rollback chaos.
The limit.
System.LimitException: Too many DML statements: 151
Salesforce allows 150 DML statements per transaction. Exceed it and the transaction dies mid-flight, leaving data in an inconsistent state.
150
Max DML statements per transaction
151
The statement that crashes the batch
3 hrs
Average downtime from this error
Bad vs good.
OpportunityTriggerHandler.clsAnti-pattern
// ❌ BAD: DML inside a for loop
// Each iteration runs a separate DML operation
public void updateOpportunities(List<Opportunity> opps) {
for (Opportunity opp : opps) {
// DML operation inside the loop!
opp.StageName = 'Closed Won';
opp.CloseDate = Date.today();
update opp; // 1 DML per iteration
}
// With 200 opportunities = 200 DML statements
// Limit is 150. Crash at 151.
}OpportunityTriggerHandler.clsFixed
// ✅ GOOD: Bulkified DML operations
// Single DML statement for all records
public void updateOpportunities(List<Opportunity> opps) {
// Update all records in memory
for (Opportunity opp : opps) {
opp.StageName = 'Closed Won';
opp.CloseDate = Date.today();
}
// Single DML operation
update opps;
// 1 DML total, regardless of record count
}The fix.
Collect records into lists and perform DML once outside the loop. Jataka measures actual DML counts against production-scale data before merge.
Catch this before production.
Book a pilot and watch Jataka block this exact anti-pattern on your next PR.