Avoid triggering table logic on temporary records
When a developer creates a temporary record for in-memory processing — building a buffer, staging data for export, or accumulating values — they sometimes call Insert(true), Modify(true), or Validate out of habit, copying the pattern from code that operates on persisted records.
Passing true for RunTrigger executes the table’s OnInsert, OnModify, or OnDelete trigger. Calling Validate executes the field’s OnValidate trigger. When these triggers run on a temporary record variable, the temporary scope no longer applies — the trigger code can cause unintended database changes because the record is no longer treated as temporary. A temporary "Sales Header" record that calls Insert(true) runs the same OnInsert trigger that creates number series entries and dimension records in production tables.
Pass false for the RunTrigger parameter (or omit it — the default is false). Replace Validate calls with direct field assignment.
Example
procedure TempSalesHeader(CustomerNo: Code[20])
var
TempSalesHeader: Record "Sales Header" temporary;
begin
TempSalesHeader.Init();
TempSalesHeader.Validate("Sell-to Customer No.", CustomerNo); // Avoid triggering table logic on temporary records [PC0027]
TempSalesHeader.Insert(true); // Avoid triggering table logic on temporary records [PC0027]
end;Assign fields directly and pass false for RunTrigger (or omit the argument):
procedure TempSalesHeader(CustomerNo: Code[20])
var
TempSalesHeader: Record "Sales Header" temporary;
begin
TempSalesHeader.Init();
TempSalesHeader."Sell-to Customer No." := CustomerNo;
TempSalesHeader.Insert();
end;When the diagnostic is reported
Insert(true),Modify(true),Delete(true), orDeleteAll(true)is called on a temporary record variable.ModifyAll(Field, Value, true)is called on a temporary record variable with the third argument set totrue.Validateis called on a temporary record variable.
Exception
The diagnostic is not raised when the table itself is defined with TableType = Temporary. Triggers in such tables are designed to operate on temporary data, so running them is expected.
table 50100 "My Buffer Table"
{
TableType = Temporary;
fields
{
field(1; "Code"; Code[20]) { }
}
}If a temporary variable genuinely needs trigger execution — for example, when the trigger code has been specifically written to handle temporary records — suppress the diagnostic with a pragma:
TempSalesHeader.Init();
TempSalesHeader."Sell-to Customer No." := CustomerNo;
#pragma warning disable PC0027 // OnInsert logic is safe for temporary records
TempSalesHeader.Insert(true);
#pragma warning restore PC0027See also
- Temporary Tables on Microsoft Learn
- Insert, Modify, ModifyAll, Delete, DeleteAll, and Truncate methods on Microsoft Learn