AccessLevel Class
Defines the different modes, such as system or user mode, that Apex database operations execute in.
By default, Apex code runs in user mode, which means that the current user’s object permissions, field-level security, and sharing rules are enforced. You can set a specific DML method to system mode, where the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords.
Many of the DML methods of the System.Database and System.Search classes include an accessLevel parameter to specify the execution mode.
If the user running this Apex code doesn’t have write access to the Account object, the Database.insert() method returns an error.
In contrast, this example shows the method running in system mode. The success of the insert doesn’t depend on whether the user running the Apex code has create access to the Account object.
The following are methods for AccessLevel.
-
withPermissionSetId(permissionSetId) (Developer Preview)
Supports database and search operations to be run with permissions specified in a permission set. Apex enforces field-level security (FLS) and object permissions as per the specified permission set, in addition to the running user’s permissions.
Supports database and search operations to be run with permissions specified in a permission set. Apex enforces field-level security (FLS) and object permissions as per the specified permission set, in addition to the running user’s permissions.
Feature is available as a developer preview. Feature isn’t generally available unless or until Salesforce announces its general availability in documentation or in press releases or public statements. All commands, parameters, and other features are subject to change or deprecation at any time, with or without notice. Don’t implement functionality developed with these commands or tools in a production environment. You can provide feedback and suggestions for the “Permission Sets with User Mode” feature in the Trailblazer Community.
This feature is available in scratch orgs where the ApexUserModeWithPermset feature is enabled. If the feature isn’t enabled, Apex code with this feature can be compiled but not executed.
public System.AccessLevel withPermissionSetId(String permissionSetId)
- permissionSetId: Type: String Permissions in the specified permission set are enforced while running user-mode DML operations, in addition to the running user’s permissions.
Type: Access Level Class
This example runs the AccessLevel.withPermissionSetId() method with the specified permission set and inserts a custom object.
The following are properties for AccessLevel.
-
Execution mode in which the the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords.
-
Execution mode in which the object permissions, field-level security, and sharing rules of the current user are enforced.
Execution mode in which the the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords.
public System.AccessLevel SYSTEM_MODE {get;}
Type: System.AccessLevel
Execution mode in which the object permissions, field-level security, and sharing rules of the current user are enforced.
public System.AccessLevel USER_MODE {get;}
Type: System.AccessLevel