SOQL Query on FieldPermissions

64 views Asked by At

I want to list out Read and Write permissions for a few fields on an object from a profile. I have a profile named CAPI and under the profile I want to find out all the field permissions from Account object. I've constructed this query for it

SELECT SObjectType, Field, PermissionsRead, PermissionsEdit FROM FieldPermissions WHERE SObjectType = 'Account' AND Field IN('Name','ShippingStreet','ShippingCity') AND Parent.Profile.Name  = 'capi'

But no data gets exported when I execute it. What am I doing wrong? Any suggestions would be appreciated.

2

There are 2 answers

0
jm. On

First of all, fields in FieldPermissions objects follow the Object.FieldName pattern e.g. Account.Phone.

Second, there is no fields like ShippingStreet and ShippingCity on Account because they are part of a compound field called ShippingAddress.

As for the last, there is no permission to Name field listed in FieldPermissions object, as permission to this field depends on object permission. So your query should look like

SELECT SObjectType, Field, PermissionsRead, PermissionsEdit FROM FieldPermissions WHERE SObjectType = 'Account' AND Parent.Profile.Name  = 'capi' AND Field IN ('Account.ShippingAddress')
0
francisco On

I saw this reference here and think it can help you:

SELECT Id, SObjectType, PermissionsRead, PermissionsEdit, Parent.label, Parent.IsOwnedByProfile
FROM ObjectPermissions
WHERE (ParentId
IN (SELECT PermissionSetId
FROM PermissionSetAssignment
WHERE Assignee.Name = 'capi'))
AND
(PermissionsRead = true)
AND
(PermissionsEdit = true)