8

I am looking to see if it is possible to compare field level security between profiles using a SOQL statement. Is this possible please?

1
  • Any examples you maybe able to provide how to see the FLS by object for each profile would be a huge help. Thanks!
    – Matt Brown
    Commented Apr 7, 2015 at 16:46

3 Answers 3

18

Here is how you can get the Field Level Security for particular profile:

SELECT Id, Field, SObjectType, PermissionsRead, PermissionsEdit 
FROM FieldPermissions 
WHERE parentId IN ( SELECT id 
                    FROM permissionset 
                    WHERE PermissionSet.Profile.Name = 'System Administrator') 

Depending upon the objects in your org, the above query would return number of records i.e. each record represents a field on each object. So for 20 objects with each of them having 20-50 custom fields it would return 20*50 number of records.

You can restrict the number of records by looking at a specific sObject. Ex:

SELECT Id, Field, SObjectType, PermissionsRead, PermissionsEdit 
FROM fieldPermissions 
WHERE SObjectType = 'Opportunity' 
AND parentId in ( SELECT id 
                  FROM permissionSet 
                  WHERE PermissionSet.Profile.Name = 'System Administrator') 

Hope this helps.

1
  • Can I get the FLS based on the user and object? Commented Apr 30, 2019 at 17:21
0

I believe you can get basic info like filterable, updateable etc using the field portion of the DescribeSObjectResult. But, it is not complete and is only for the current user. If you really need to get this info using non-metadata methods, you might have to go to Andrew Fawcett's excellent metadata wrapper classes.

Good luck!

0

// Find if Profile has Read, Edit access to specific field

SELECT Id, Parent.Profile.Name, Field, SObjectType, PermissionsRead, PermissionsEdit
FROM FieldPermissions 
WHERE parentId IN ( SELECT Id 
                    FROM permissionset 
                    WHERE PermissionSet.Profile.Name IN (YOUR PROFILES)) 
AND SObjectType = YOUR SOBJECT AND Field = YOUR FIELD
1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Oct 26, 2023 at 13:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .