Loading
Scalability
ApexGuru Antipattern: DML in a Loop

ApexGuru Antipattern: DML in a Loop

Executing DML operations (insert, update, and delete) inside loops causes excessive resource consumption and can hit governor limits. Instead, batch DML operations by storing records in a list and performing the DML operation one time outside of the loop.

Scope

Detection only

Detection Example

apex
 for (Account acc : accounts) {
      insert acc;
 
Indlæser
Salesforce Help | Article