In this blog, we will get the idea on how we can check current if the logged-in user has Read/Write/Update access to any specific entity or not.
We have one Boolean type PCF control on the Account entity. Based on the Yes / No value of PCF control, we want to create a Contact entity record for the Current Account.
We will achieve this with the help of context.utils.hasEntityPrivilege function that is used to detect whether the current logged-in user has Read/Write permission for a specific entity or not. In our case, we need to check if the active users have ‘to Create’ permission for the Contact entity record. Please find the below code that we have used to find out the same.
contact = Entity type name for which we have to find privilege details for the said entity.
1 = It indicates Entity privilege type such as Read, Write, etc. In the above scenario, we check for Create privilege so 1 is associated with ‘Create’. Please find some other Entity type names with their code:
None = 0
Create = 1
Read = 2
Write = 3
Delete = 4
3 = It indicates the entity privilege depth of the specified entity. It has the following values:
None = -1
Basic = 0
Local = 1
Deep = 2
Global = 3
So, by calling this function, we found that the current logged in user has ‘to Create’ permission for Contact entity record as shown in the below screenshot:
As per the result given by context.utils.hasEntityPrivilege function, we take a decision to create a record contact entity record or not.
Using context.utils.hasEntityPrivilege, we can easily retrieve the current logged in user privilege details.