Use return value for better error handling
Single-record read methods like Get() and FindFirst() return an optional Boolean. When the return value is omitted, the platform’s behavior changes:
If you omit this optional return value and the operation does not execute successfully, a runtime error will occur.
— Record.Get() Method on Microsoft Learn
That runtime error is a generic platform message — it tells the user which record is missing but not why it matters or what to do next. Check the return value to provide a specific error message, exit early, or fall back to alternative logic.
Example
The following code discards the return value of Get():
procedure MyProcedure()
var
Customer: Record Customer;
begin
Customer.Get('10000'); // Use return value for better error handling [AC0030]
end;To fix this, check the return value and handle the case when the record is not found. When the record is required, raise a clear error:
procedure MyProcedure(CustomerNo: Code[20])
var
Customer: Record Customer;
begin
if not Customer.Get(CustomerNo) then
Error('Customer %1 was not found.', CustomerNo);
end;When the calling logic can proceed without the record, exit early:
procedure MyProcedure()
var
SalesSetup: Record "Sales & Receivables Setup";
begin
if not SalesSetup.Get() then
exit;
// ...
end;Error handling
To handle errors consider using the ErrorInfo data type. This provides a structured way to capture and relay detailed error information. For more practical guidance and examples, check out this article: ErrorInfo Data Type & Collectible Errors by Tomas Kapitan.
procedure GetCustomer(CustomerNo: Code[20])
var
Customer: Record Customer;
MyErrorHandler: Codeunit "My Error Handler";
begin
if not Customer.Get(CustomerNo) then
MyErrorHandler.EmitErrorInfo(CustomerNotFound, CustomerNo);
end;In certain scenarios, implementing an actionable error can further enhance the user experience by guiding users toward resolving the issue.
When the diagnostic is reported
The rule flags any call to a single-record read method where the return value is discarded — the call appears as a standalone statement rather than inside an if, an assignment, or another expression.
Affected methods:
Record.Get()Record.GetBySystemId()Record.Find()Record.FindFirst()Record.FindLast()
See also
- LC0097 - Avoid mixing exit() and named return variable assignments
- PC0038 - Not all code paths return a value
- Record.Get() Method on Microsoft Learn
- Get, Find, and Next Methods on Microsoft Learn
- if not then exit on alguidelines.dev