Since I couldn't think of how to write this query off the top of my head, I thought it might be worth sharing. How can I query which Profiles
have Read
permission on a specific object? I knew it would have something to do with ObjectPermissions
and PermissionSet
, but had to look up the documentation for both to piece it together.
Add a comment
|
1 Answer
The first query I got to work was on the ObjectPermissions
object:
SELECT Parent.Profile.Name FROM ObjectPermissions
WHERE Parent.IsOwnedByProfile = true AND SObjectType = 'MyObject__c'
This query gets exactly the data I wish, but in the Query Editor, gives the dreaded:
[object Object]
Left Inner Join
to the rescue! More palatable:
SELECT Profile.Name FROM PermissionSet
WHERE IsOwnedByProfile = true AND Id IN (
SELECT ParentId FROM ObjectPermissions
WHERE PermissionsRead = true
AND SObjectType = 'MyObject__c'
)
-
2note: github.com/forcedotcom/user-access-visualization which also caters for permission sets (as those can extend a running user's object access) -- taken from sfdcfox answer– cropredyCommented Dec 29, 2016 at 2:06