Wednesday, January 3, 2018

Compare Field-Level Permissions Between Profiles

If you want to compare field level permissions between two profiles, and you can use something like dbAmp to download your data to a SQL database, you can run a query like the following to compare two profiles.

select P1Perms.SobjectType, P1Perms.Field, P1Perms.PermissionsRead, P2Perms.PermissionsRead, P1Perms.PermissionsEdit, P2Perms.PermissionsEdit from 
(select fp.field, SobjectType, fp.PermissionsEdit, fp.PermissionsRead, profile.name from fieldpermissions fp
 join permissionset as ps on ps.id = fp.ParentId
 join profile on profile.Id = ps.ProfileId
 where profile.name = 'System Administrator (Custom)'
) as P1Perms 
left join (select fp.field, SobjectType, fp.PermissionsEdit, fp.PermissionsRead, profile.name from fieldpermissions fp
 join permissionset as ps on ps.id = fp.ParentId
 join profile on profile.Id = ps.ProfileId
 where profile.name = 'Business Development'
) as P2Perms on P1Perms.Field = P2Perms.Field and P1Perms.SobjectType = P2Perms.SobjectType
  where P1Perms.PermissionsRead <> P2Perms.PermissionsRead or P1Perms.PermissionsEdit <> P2Perms.PermissionsEdit or P2Perms.PermissionsRead is null
order by P1Perms.SobjectType, P1Perms.Field

No comments:

Post a Comment