Using Access Modifiers in AL
Access modifiers are used to set accessibility of tables, table fields, codeunits, and queries, which controls whether the object can be used from other code in your module or other modules. Access modifiers in AL are designed to create solid APIs, by limiting the symbols that dependant modules can take a reference on. Limiting the API surface can hide implementation details and allow for later refactoring of code without breaking external code.
You set the object accessibility by using the Access Property. If the Access
property isn't specified; default is Public
.
Note
In AL, access modifiers are primarily intended for designing APIs and cannot be used as a security boundary.
Access modifiers
The access modifiers that are available in AL are:
Access Modifier | Description |
---|---|
internal |
The object or field can be accessed only by code in the same module, but not from another module. Note: This accessibility level is controlled by the internalsVisibleTo setting. For more information, see JSON Files |
local |
The field can be accessed only by code in the same table or table extension where the field is defined. Note: Applies to table fields only. |
protected |
The field can be accessed only by code in the same table or table extensions of that table. Note: Applies to table fields only. |
public |
The object or field can be accessed by any other code in the same module and in other modules that references it. Note: This is the default value. |
Setting access to internal
is linked to the JSON Files setting internalsVisibleTo
.
Important
Access modifiers are only taken into consideration at compile time. For example, at compile time, a table with Access = Internal
can't be used from other modules that don't have access to the internals of the module where the table is defined, but at runtime, any module can access the table by using reflection-based mechanisms such as RecordRef
, or TransferFields
. And the OnRun
trigger can be run on internal
codeunits by using Codeunit.Run
. Setting the object accessibility level as Access = Internal;
cannot be used as a security boundary. Also see JSON Files.