Use IsEmpty method instead of Count (LC0081)

When checking if a recordset has any records, use IsEmpty instead of comparing Count to zero. The IsEmpty method is more efficient because it stops after finding the first record, while Count must enumerate all records.

Example

The following code inefficiently uses Count to check for records:

codeunit 50100 MyCodeunit
{
    procedure HasCustomers(): Boolean
    var
        Customer: Record Customer;
    begin
        exit(Customer.Count() > 0); // Use IsEmpty method instead of Count [LC0081]
    end;
}

To fix this, use IsEmpty:

codeunit 50100 MyCodeunit
{
    procedure HasCustomers(): Boolean
    var
        Customer: Record Customer;
    begin
        exit(not Customer.IsEmpty());
    end;
}

See also

  • LC0082 - Use Query or Find with Next instead of Count