Friday, 1 February 2019

How to find field access in Permission Sets and Profile?

FieldPermission is the Salesforce internal standard object. It is used to store field permissions given through Permission set and profiles. 
For example if you want to find access of custom fields like Rate__c and Compititor__c from Account object. You can use below query to find the field usage:
SELECT SobjectType,Field, PermissionsRead,PermissionsEdit, Parent.Name, ParentId FROM FieldPermissions WHERE PermissionsRead = True and Field in ('Account.Rate__c','Account.From1__c','Account.Compititor__c') AND SobjectType = 'Account'
For Read access you can use 'PermissionsRead' and for Edit access, you can use PermissionsEdit field of FieldPermissions object. 

ParentId contains either permission set id. If you looking for field access in permission set then you can use Parent Id as it is But if you are looking for profile id then please follow:

  • When you assign FLS through profile, Salesforce stores ParentId in the form of Permission set. 
  • So to get actual profile ids, you have to add Parent.Name field in the query. 
  • That will give you 'X00e600...' id. Remove X00 from the id and rest of it is profile id. 

No comments:

Post a Comment

Why to use Database.Stateful()?

Database Stateful is interface. It is used in batch classes to maintain the state of the class across transactions i.e. if you want to use ...