Do not use Object IDs as object references (LC0003)
When referencing objects in variable declarations, property values, built-in method invocations, or event subscriber attributes, use the object name instead of a numeric Object ID. Numeric IDs are not readable and cannot be safely renamed.
A code fix is available for this diagnostic.
Examples
Variable declarations
Using a numeric ID to reference an object in a variable declaration:
codeunit 50100 MyCodeunit
{
var
MyTable: Record 50100;
}Use the object name instead:
codeunit 50100 MyCodeunit
{
var
MyTable: Record MyTable;
}
This applies to all data types that reference objects: Record, Codeunit, Page, Report, Xmlport, and Query.
Built-in method invocations
Using a numeric ID as the first argument in a static method call:
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
begin
Codeunit.Run(50100);
end;
}Use the object name instead:
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
begin
Codeunit.Run(Codeunit::MyCodeunit);
end;
}
This also applies to Page.Run(), Page.RunModal(), Report.Run(), Query.SaveAsCsv(), Xmlport.Run(), Xmlport.Export(), Xmlport.Import(), RecordRef.Open(), and similar methods.
Note:
Page.Run(0)is a valid use case and will not trigger this diagnostic.
EventSubscriber attributes
Using a numeric ID in an EventSubscriber attribute:
codeunit 50100 MyCodeunit
{
[EventSubscriber(ObjectType::Codeunit, 50100, MyIntegrationEvent, '', false, false)]
local procedure MyEventSubscriber()
begin
end;
}Use the object name instead:
codeunit 50100 MyCodeunit
{
[EventSubscriber(ObjectType::Codeunit, Codeunit::MyCodeunit, MyIntegrationEvent, '', false, false)]
local procedure MyEventSubscriber()
begin
end;
}