BCQuality rule · performanceAL Developmentofficial - Microsoftderived - from the source, no model text

Avoid cloning records before Modify or Delete in loops

Microsoft's AL database-method performance guidance states that cloning an iterated record before Modify or Delete restarts the SQL SELECT and issues an extra SQL statement for every row.

Rule on GitHub · microsoft layer · performance · BC all · tier official · derived

Description

Microsoft’s AL database-method performance guidance states that cloning an iterated record before Modify or Delete restarts the SQL SELECT and issues an extra SQL statement for every row. The runtime treats Record.Copy, RecordRef.GetTable, and passing a record by value to a writing helper as clones in this situation.

Best Practice

Use FindSet(true) when the loop writes the traversed rows, and call Modify or Delete on that iterating record variable. If generic code is required, open and iterate the RecordRef directly instead of calling GetTable for each typed record. Keep a per-row loop when validation or row-specific behavior is required; this rule does not imply that ModifyAll or DeleteAll is equivalent.

See sample: avoid-cloning-records-before-modify-delete-in-loops.good.al.

Anti Pattern

Inside an active traversal, copy the current row, convert it with RecordRef.GetTable, or pass it without var to a helper, then call Modify or Delete on that clone. Do not flag read-only snapshots, temporary records, or copies used to write a different target table; the documented extra-statement concern is clone-before-write on the traversed table.

See sample: avoid-cloning-records-before-modify-delete-in-loops.bad.al.

Examples

Names

Changed by


From microsoft/BCQuality at a4593a1, MIT License, Copyright (c) 2026 Microsoft Corporation (license).