Use return value for better error handling (AC0030)
Database read methods, like Record.Get(), returns a boolean indicating whether the record was successfully retrieved. Failing to use this return value can lead to uncaught errors, poor error handling, and a lack of actionable feedback for users when something goes wrong.
By checking the return value, you can provide meaningful error messages, implement fallback logic, or prevent downstream code from executing with invalid data.
Example
The following code discards the return value of a database read method:
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
Customer: Record Customer;
begin
Customer.Get('10000'); // The return value of the 'Get' method must be used to improve error handling or provide meaningful feedback to the user. [AC0030]
end;
}
To fix this, check the return value and handle the case when the record is not found:
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
Customer: Record Customer;
begin
if not Customer.Get('10000') then
Error('Customer 10000 was not found.');
end;
}