Wednesday 9 May 2018

How to fetch field permission details for all profiles in SOQL query

Here is the way to fetch field permission details for all profiles in SOQL query by using FieldPermissions object.

Query specific field permission for all Profiles:

  1. SELECT Profile.Name FROM PermissionSet WHERE IsOwnedByProfile = TRUE AND Id IN (SELECT ParentId FROM FieldPermissions WHERE FIELD ='Payment__c.Firm__c' AND SobjectType = 'Payment__c' AND PermissionsRead = TRUE AND PermissionsEdit = FALSE) ORDER BY Profile.Name

PermissionsRead --> View permission for the field.
PermissionsEdit --> Edit permission for the field.

The below approach also works but the profile name will be displayed as [Object Object] in Query Editor,


  1. SELECT Parent.Profile.Name FROM FieldPermissions WHERE FIELD = 'Payment__c.Firm__c'  AND Parent.IsOwnedByProfile = TRUE AND SobjectType ='Payment__c' AND PermissionsRead = TRUE AND PermissionsEdit = FALSE ORDER BY Profile.Name

Reference:

Field Permission

Object Permission

How to fetch object permission for all profiles in SOQL query

You may be in a situation to verify object permission details for all or specific profile. So you may check object details from UI one by one by navigating each profile, and this will be time-consuming. Instead, you can fetch details by querying ObjectPermission. Here is the example,


Query specific object permission for all Profiles:

  1. SELECT Profile.Name FROM PermissionSet WHERE IsOwnedByProfile = TRUE AND Id IN (SELECT ParentId FROM ObjectPermissions WHERE PermissionsRead = TRUE AND SObjectType = 'CustomObject__c') ORDER BY Profile.Name

You can check all object level permission in the query. Such as,
PermissionsRead 
PermissionsCreate
PermissionsEdit
PermissionsDelete
PermissionsViewAllRecords
PermissionsModifyAllRecords


The below approach also works but the profile name will be displayed as [Object Object] in Query Editor,

  1. SELECT Parent.Profile.Name FROM ObjectPermissions WHERE Parent.IsOwnedByProfile = TRUE AND SObjectType = 'CustomObject__c'

Reference:

Stackexchange

Object Permission

Friday 4 May 2018

Property 'userLicense' not valid in version 38.0 Salesforce

You will get below error message when you try to deploy PermissionSet with Package Version of 38.0

Property 'userLicense' not valid in version 38.0 Salesforce

Solution:

If you open your permission set metadata file you will see tag like below,
    <userLicense>Salesforce</userLicense>

From API Version 38.0 or later, then you have to change as license only.
    <license>Salesforce</license>


As per Salesforce documentation,

userLicense tag is Deprecated. The user license for the permission set. A user license determines the baseline of features that the user can access. Every user must have exactly one user license. Available up to API version 37.0. In API version 38.0 and later, use license.

Reference:
Permission Set Metadata API

How to Check if the Current/Running User has a Custom Permission in Salesforce?

FeatureManagement:

For this requirement we can use FeatureManagement.checkPermission method to identify Current/Running User has a Custom Permission. This method available from Winter 18 onwards.

checkPermission(apiName)
Checks whether a custom permission is enabled.

   Signature
      public static Boolean checkPermission(String apiName)
   Parameters
      apiName
   Type: String

Example:
  1. if(FeatureManagement.checkPermission('Chat_CustomPermission_Access')){
  2.     // Perform some logics.
  3. }

Reference:
FeatureManagement

Activities: Assign Tasks to a Queue Salesforce Lightning

Salesforce announced to assign Tasks to a Queue beginning from Spring'20 release. How does it work? In Setup, enter Queues in th...