-
Notifications
You must be signed in to change notification settings - Fork 13
CanTheUser
STATUS: ACTIVE
A reusable, intuitive library for determining whether or not the
current use can create, read, edit, or delete objects as well as
determining if the user has access or update permissions on specific fields.
This class name was chosen to facilitate easy-to-understand and read code.
Whenever you need to check FLS or CRUD access your code reads like this
if(CanTheUser.read(new account())){}
making the calling and use of this
code easy and intuitive.
This class' name was chosen to facilitate easy-to-understand and read
code. Whenever you need to check FLS or CRUD access your code reads like
this
if(CanTheUser.read(new account())){}
making the calling and use of this
code easy and intuitive.
This variable stores, within the same transaction, all previously calculated FLS results for an object. This prevents multiple calls to this library within the same transaction from executing more than a single describe call.
TESTVISIBLE
A method to determine if the running user can perform the specified CRUD operation on the specified object, or object type.
Param | Description |
---|---|
obj |
the object type to check |
permission |
create, read, update or delete |
Type | Description |
---|---|
Boolean | Boolean true if the user can perform the specified CRUD operation on the specified object |
System.debug(CanTheUser.crud(new Account(), CanTheUser.CrudType.READABLE));
TESTVISIBLE
a list accepting version of the crud method. It returns CRUD results for the first object in the list. Use this method to see if the running user can, for instance, Create an Account, Contact, or Opportunity
Param | Description |
---|---|
objs |
List the list of SObjects to check |
permission |
CrudType the CRUD type to check ie: Create |
Type | Description |
---|---|
Boolean | Boolean true if the user can perform the specified CRUD operation on the first object in the list |
TESTVISIBLE
A method to determine if the running user can perform the specified CRUD operation on the specified object, or object type.
Param | Description |
---|---|
objectName |
String the name of the object to check |
permission |
CrudType the CRUD type to check ie: Create |
Type | Description |
---|---|
Boolean | Boolean true if the user can perform the specified CRUD operation on the specified object |
convenience api for determining if the running user can create the specified object
Param | Description |
---|---|
obj |
Object type to check create permissions on |
Type | Description |
---|---|
Boolean | Boolean true if the user can create the specified object |
System.debug(CanTheUser.create(new Account()));
convenience api for determining if the running user can create the specified object
Param | Description |
---|---|
objs |
list of objects. Only the first will be checked. (logically, a list is of uniform type and, and if the user can create one) |
Type | Description |
---|---|
Boolean | Boolean true if the user can create the first object in the list |
convenience api for determining if the running user can create the specified object
Param | Description |
---|---|
objName |
Object type to check create permissions on |
Type | Description |
---|---|
Boolean | Boolean true if the user can create the specified object |
System.debug(CanTheUser.create('Account'));
convenience api for determining if the running user can read / access the specified object
Param | Description |
---|---|
obj |
object type to check read permissions on |
Type | Description |
---|---|
Boolean | Boolean true if the user can read the specified object |
System.debug(CanTheUser.read(new Account()));
convenience api for determining if the running user can read / access the specified objects
Param | Description |
---|---|
objs |
object type to check read permissions on |
Type | Description |
---|---|
Boolean | Boolean true if the user can read the specified object |
convenience api for determining if the running user can read the specified object
Param | Description |
---|---|
objName |
Object type to check read permissions on |
Type | Description |
---|---|
Boolean | Boolean true if the user can read the specified object |
System.debug(CanTheUser.read('Account'));
convenience api for determining if the running user can edit / update the specified object
Param | Description |
---|---|
obj |
object type to check edit permissions on |
Type | Description |
---|---|
Boolean | Boolean true if the user can edit the specified object |
System.debug(CanTheUser.edit(new Account()));
convenience api for determining if the running user can edit / update the specified objects
Param | Description |
---|---|
objs |
object type to check edit permissions on |
Type | Description |
---|---|
Boolean | Boolean true if the user can edit the specified object |
convenience api for determining if the running user can edit the specified object
Param | Description |
---|---|
objName |
Object type to check edit permissions on |
Type | Description |
---|---|
Boolean | Boolean true if the user can edit the specified object |
System.debug(CanTheUser.edit('Account'));
convenience api for determining if the running user can upsert (insert and update) the specified objects
Param | Description |
---|---|
obj |
object type to check edit permissions on |
Type | Description |
---|---|
Boolean | Boolean true if the user can upsert the specified object |
System.debug(CanTheUser.ups(new Account()));
convenience api for determining if the running user can edit / update the specified objects
Param | Description |
---|---|
objs |
object type to check upsert permissions on |
Type | Description |
---|---|
Boolean | Boolean true if the user can upsert the specified object |
convenience api for determining if the running user can upsert the specified object
Param | Description |
---|---|
objName |
Object type to check upsert permissions on |
Type | Description |
---|---|
Boolean | Boolean true if the user can upsert the specified objects |
System.debug(CanTheUser.ups('Account'));
convenience api for determining if the running user can delete/destroy the specified object
Param | Description |
---|---|
obj |
object type to check destroy permissions on |
Type | Description |
---|---|
Boolean | Boolean true if the user can delete the specified object |
System.debug(CanTheUser.destroy(new Account()));
convenience api for determining if the running user can delete the specified object
Param | Description |
---|---|
objs |
Object type to check delete permissions on |
Type | Description |
---|---|
Boolean | Boolean true if the user can delete the specified object |
convenience api for determining if the running user can delete the specified object
Param | Description |
---|---|
objName |
Object type to check create permissions on |
Type | Description |
---|---|
Boolean | Boolean true if the user can delete the specified object |
System.debug(CanTheUser.destroy('Account'));
public static method to determine if a given field on a given object is Accessible (readable)
Param | Description |
---|---|
obj |
the object in question, in string form |
field |
the field in question in SObjectField form |
Type | Description |
---|---|
Boolean | Boolean true if the user can read the specified field on the specified object |
System.debug(CanTheUser.flsAccessible('Account', 'Name'));
bulk form of flsAccessible
Param | Description |
---|---|
obj |
Obj name on which to check |
fields |
Set of Fields to check for accessibility. |
Type | Description |
---|---|
Map<String,Boolean> |
Map<String, Boolean> where the key is the field name and the value is the accessibility |
String[] fields = new String[]{'Name', 'ShippingStreet'};
System.debug(CanTheUser.bulkFLSAccessible('Account', fields));
public static method to determine if a given field on a given object is Updatable.
Param | Description |
---|---|
obj |
the string version of an object name |
field |
the field to check |
Type | Description |
---|---|
Boolean | Boolean true if the user can update the specified field on the specified object |
System.debug(CanTheUser.flsUpdatable('Account', 'Name'));
bulk form of flsUpdatable call
Param | Description |
---|---|
obj |
Name of the object |
fields |
Set of Field names to check |
Type | Description |
---|---|
Map<String,Boolean> |
Map<String, Boolean> where the key is the field name and the value is the updatability |
String[] fields = new String[]{'Name', 'ShippingStreet'};
System.debug(CanTheUser.bulkFLSUpdatable('Account', fields));
Abstracted method for retrieving or calculating (memoization) of the FLS for a given field on a given object.
Param | Description |
---|---|
obj |
String version of object name to check |
field |
String version of the field to check |
checkType |
Enum of Accessible or Updatable. |
Type | Description |
---|---|
Boolean | Boolean |
Calculates the FLS for a given object type
Param | Description |
---|---|
objType |
String name of the object type |
Type | Description |
---|---|
Map<String,Map<FLSType,Boolean>> | Map<String, Map<FLSType, Boolean>> |
An ENUM specifying the various types of CRUD operations
An ENUM specifying the various types of FLS operations available.