Record instance isolation level (LC0031)

When working with records that require specific isolation levels (such as for locking), the isolation level should be set explicitly on the record variable. This ensures predictable behavior and prevents race conditions.

A code fix is available for this diagnostic.

Example

The following code modifies a record without proper isolation:

codeunit 50100 MyCodeunit
{
    procedure UpdateCounter()
    var
        Counter: Record Counter;
    begin
        Counter.Get(); // Record instance isolation level [LC0031]
        Counter.Value += 1;
        Counter.Modify();
    end;
}

To fix this, set the appropriate isolation level:

codeunit 50100 MyCodeunit
{
    procedure UpdateCounter()
    var
        Counter: Record Counter;
    begin
        Counter.LockTable();
        Counter.Get();
        Counter.Value += 1;
        Counter.Modify();
    end;
}