在Salesforce中使用SOQL查找Profile相关权限

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/itsme_web/article/details/81670937

Query specific field permission for all Profiles:

SELECT Profile.Name FROM PermissionSet WHERE IsOwnedByProfile = TRUE AND Id IN (SELECT ParentId FROM FieldPermissions WHERE FIELD ='Payment__c.Firm__c' AND SobjectType = 'Payment__c' AND PermissionsRead = TRUE AND PermissionsEdit = FALSE) ORDER BY Profile.Name

PermissionsRead --> View permission for the field.
PermissionsEdit --> Edit permission for the field.

The below approach also works but the profile name will be displayed as [Object Object] in Query Editor,

SELECT Parent.Profile.Name FROM FieldPermissions WHERE FIELD = 'Payment__c.Firm__c'  AND Parent.IsOwnedByProfile = TRUE AND SobjectType ='Payment__c' AND PermissionsRead = TRUE AND PermissionsEdit = FALSE ORDER BY Profile.Name

Query specific object permission for all Profiles:

SELECT Profile.Name FROM PermissionSet WHERE IsOwnedByProfile = TRUE AND Id IN (SELECT ParentId FROM ObjectPermissions WHERE PermissionsRead = TRUE AND SObjectType = 'CustomObject__c') ORDER BY Profile.Name

You can check all object level permission in the query. Such as,
PermissionsRead 
PermissionsCreate
PermissionsEdit
PermissionsDelete
PermissionsViewAllRecords
PermissionsModifyAllRecords

【参考】:
Field Permission | Object Permission | Query Which Profiles Have Read Access To Specific Object?

猜你喜欢

转载自blog.csdn.net/itsme_web/article/details/81670937