SEL_ObjectPermission
Class · Group: Selectors
global inherited sharing class SEL_ObjectPermissionProvides methods for querying and evaluating user access permissions on Salesforce objects. Simplifies permission checks by exposing operations such as read or create access for single or multiple users via PermissionSetAssignment with semi-join into ObjectPermissions.
Example
Boolean canRead = SEL_ObjectPermission.hasReadAccess(userId, Account.SObjectType);
Boolean canCreate = SEL_ObjectPermission.hasCreateAccess(userId, Case.SObjectType);
Set<Id> readers = SEL_ObjectPermission.hasReadAccess(userIds, Account.SObjectType);Methods
| Method | Description |
|---|---|
| global static Boolean hasAccess(SEL_ObjectPermission.ObjectPermissionType objectAccessLevel, Id userId, SObjectType objectType) | Checks if a specific user has the required access level for a particular SObjectType. |
| global static Set<Id> hasAccess(SEL_ObjectPermission.ObjectPermissionType objectAccessLevel, Set<Id> userIds, SObjectType objectType) | Verifies if multiple users have a specified access level for a given object type. |
| global static Boolean hasCreateAccess(Id userId, SObjectType objectType) | Checks if a specified user has create access to a particular object type. |
| global static Boolean hasReadAccess(Id userId, SObjectType objectType) | Determines if a specified user has read access to a particular Salesforce object type. |
| global static Set<Id> hasReadAccess(Set<Id> userIds, SObjectType objectType) | Checks if a set of specified users has read access to a given object type. |
hasAccess
global static Boolean hasAccess(SEL_ObjectPermission.ObjectPermissionType objectAccessLevel, Id userId, SObjectType objectType)Checks if a specific user has the required access level for a particular SObjectType.
Parameters
| Parameter | Type | Description |
|---|---|---|
objectAccessLevel | SEL_ObjectPermission.ObjectPermissionType | The ObjectPermissionType (e.g., CREATE, READ) to check for |
userId | Id | The Id of the user to check access for |
objectType | SObjectType | The SObjectType of the object for which access is being checked |
Returns Boolean — True if the user has the specified access level; otherwise, false
Example
Boolean result = SEL_ObjectPermission.hasAccess(new ObjectPermissionType(), recordId, Account.SObjectType);global static Set<Id> hasAccess(SEL_ObjectPermission.ObjectPermissionType objectAccessLevel, Set<Id> userIds, SObjectType objectType)Verifies if multiple users have a specified access level for a given object type.
Parameters
| Parameter | Type | Description |
|---|---|---|
objectAccessLevel | SEL_ObjectPermission.ObjectPermissionType | The ObjectPermissionType (e.g., MODIFY_ALL, VIEW_ALL) to check for |
userIds | Set | A Set of User Ids to check access for |
objectType | Id | The SObjectType of the object for which access is being checked |
Returns Id — The Ids of users that have the required access level
Example
Set<Id> result = SEL_ObjectPermission.hasAccess(new ObjectPermissionType(), recordIds, Account.SObjectType);hasCreateAccess
global static Boolean hasCreateAccess(Id userId, SObjectType objectType)Checks if a specified user has create access to a particular object type.
Parameters
| Parameter | Type | Description |
|---|---|---|
userId | Id | The Id of the User to check for create access |
objectType | SObjectType | The SObjectType of the object to check access for |
Returns Boolean — True if the user has create access; otherwise, false
Example
Boolean result = SEL_ObjectPermission.hasCreateAccess(recordId, Account.SObjectType);hasReadAccess
global static Boolean hasReadAccess(Id userId, SObjectType objectType)Determines if a specified user has read access to a particular Salesforce object type.
Parameters
| Parameter | Type | Description |
|---|---|---|
userId | Id | The Id of the User to check for read access |
objectType | SObjectType | The SObjectType of the object to check access for |
Returns Boolean — True if the user has read access to the object; otherwise, false
Example
Boolean result = SEL_ObjectPermission.hasReadAccess(recordId, Account.SObjectType);global static Set<Id> hasReadAccess(Set<Id> userIds, SObjectType objectType)Checks if a set of specified users has read access to a given object type.
Parameters
| Parameter | Type | Description |
|---|---|---|
userIds | Set | A Set of User Ids to check for read access |
objectType | Id | The SObjectType of the object to check access for |
Returns Id — The Ids of users that have read access to the object type
Example
Set<Id> result = SEL_ObjectPermission.hasReadAccess(recordIds, Account.SObjectType);Inner Classes
| Class | Description |
|---|---|
| ObjectPermissionType | A Permission that a User might have on a SObjectType. |