Event publisher methods should not be public
AL developers often leave event publishers at the default public access level, assuming external subscribers need to see the method. They don’t — the access modifier only controls who can raise the event. External extensions can subscribe to a local or internal event publisher exactly as they would to a public one.
If you don’t want the event publisher to be raised from other objects than the one defining it, make it a local method by affixing it with
local. The event still remains available to event subscribers from other objects.— Publishing Events on Microsoft Learn
A public event publisher becomes part of the extension’s public API surface. AppSourceCop rule AS0025
treats parameter changes on public events as breaking changes — you cannot add, remove, or rename parameters without breaking dependent extensions that raise the event. With a local or internal access modifier, adding parameters is explicitly allowed.
Declare event publishers as local or internal to keep them fully subscribable while reserving the freedom to extend their signatures in future versions. The rule applies to all event attribute types: IntegrationEvent, BusinessEvent, InternalEvent, and ExternalBusinessEvent.
Example
The following event publisher is public:
codeunit 50100 MyCodeunit
{
[IntegrationEvent(false, false)]
procedure OnBeforeSomething() // Event publisher methods should not be public [AC0024]
begin
end;
}Declare the event publisher as local when the event is only raised within the same object:
codeunit 50100 MyCodeunit
{
[IntegrationEvent(false, false)]
local procedure OnBeforeSomething()
begin
end;
}Use internal when other objects in the same extension need to raise the event:
codeunit 50100 MyCodeunit
{
[IntegrationEvent(false, false)]
internal procedure OnBeforeSomething()
begin
end;
}Code fix
The code fix changes the event publisher’s access modifier to local.
See also
- AC0012 — Integration events must not be declared in codeunits with Access set to Internal