---
schema_version: "1"
id: eb4ec3645a8923444323fa9a3c2ba0af4bcab4c838a58c0231b0337b6caf9e3c
title: "ApexGuru Antipattern: DML in a Loop"
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/xcloud/264-0-0/apexguru_antipattern_dml_in_loop.md
canonical_url: https://help.salesforce.com/s/articleView?id=xcloud.apexguru_antipattern_dml_in_loop.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 2822ff224852a9672ee8ed78455fdc5c24638c21b8ee9f765c5e9a9c6d0ee727
description: 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.
products:
  - Cross Cloud
release: "264"
---
# 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

```java
apex
 for (Account acc : accounts) {
      insert acc;
```