Newer Version Available
AccessLevel Class (Beta)
Namespace
Usage
By default, Apex code runs in system mode, which means that it runs with substantially elevated permissions over the user running the code. In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the current user's object permissions, field-level security, and sharing rules are enforced.
Many of the DML methods of the System.Database and System.Search classes include an accessLevel parameter to specify the execution mode.
Example
If the user running this Apex code doesn't have write access to the Account object, the Database.insert() method returns an error.
1List<Account> toInsert = new List<Account>{new Account(Name = 'Exciting New Account')};
2
3List<Database.SaveResult> sr = Database.insert(toInsert, AccessLevel.USER_MODE);
4In 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.
1List<Account> toInsert = new List<Account>{new Account(Name = 'Exciting New Account')};
2
3List<Database.SaveResult> sr = Database.insert(toInsert, AccessLevel.SYSTEM_MODE);
4AccessLevel Properties
The following are properties for AccessLevel.
SYSTEM_MODE
Signature
public System.AccessLevel SYSTEM_MODE {get;}
Property Value
Type: System.AccessLevel