6

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

  • 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 Apr 7 '15 at 16:46
12

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.

  • Can I get the FLS based on the user and object? – Ramesh S Apr 30 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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.