Skip to content

SEL_ObjectPermission

Class · Group: Selectors

apex
global inherited sharing class SEL_ObjectPermission

Provides 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

apex
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

MethodDescription
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

apex
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

ParameterTypeDescription
objectAccessLevelSEL_ObjectPermission.ObjectPermissionTypeThe ObjectPermissionType (e.g., CREATE, READ) to check for
userIdIdThe Id of the user to check access for
objectTypeSObjectTypeThe SObjectType of the object for which access is being checked

Returns Boolean — True if the user has the specified access level; otherwise, false

Example

apex
Boolean result = SEL_ObjectPermission.hasAccess(new ObjectPermissionType(), recordId, Account.SObjectType);
apex
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

ParameterTypeDescription
objectAccessLevelSEL_ObjectPermission.ObjectPermissionTypeThe ObjectPermissionType (e.g., MODIFY_ALL, VIEW_ALL) to check for
userIdsSetA Set of User Ids to check access for
objectTypeIdThe SObjectType of the object for which access is being checked

Returns Id — The Ids of users that have the required access level

Example

apex
Set<Id> result = SEL_ObjectPermission.hasAccess(new ObjectPermissionType(), recordIds, Account.SObjectType);

hasCreateAccess

apex
global static Boolean hasCreateAccess(Id userId, SObjectType objectType)

Checks if a specified user has create access to a particular object type.

Parameters

ParameterTypeDescription
userIdIdThe Id of the User to check for create access
objectTypeSObjectTypeThe SObjectType of the object to check access for

Returns Boolean — True if the user has create access; otherwise, false

Example

apex
Boolean result = SEL_ObjectPermission.hasCreateAccess(recordId, Account.SObjectType);

hasReadAccess

apex
global static Boolean hasReadAccess(Id userId, SObjectType objectType)

Determines if a specified user has read access to a particular Salesforce object type.

Parameters

ParameterTypeDescription
userIdIdThe Id of the User to check for read access
objectTypeSObjectTypeThe SObjectType of the object to check access for

Returns Boolean — True if the user has read access to the object; otherwise, false

Example

apex
Boolean result = SEL_ObjectPermission.hasReadAccess(recordId, Account.SObjectType);
apex
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

ParameterTypeDescription
userIdsSetA Set of User Ids to check for read access
objectTypeIdThe SObjectType of the object to check access for

Returns Id — The Ids of users that have read access to the object type

Example

apex
Set<Id> result = SEL_ObjectPermission.hasReadAccess(recordIds, Account.SObjectType);

Inner Classes

ClassDescription
ObjectPermissionTypeA Permission that a User might have on a SObjectType.