September 4, 2018

How to Query Object Permissions for a Profile in Salesforce?

Sample SOQL:

SELECT sObjectType, PermissionsCreate, PermissionsRead, PermissionsEdit, PermissionsDelete, PermissionsModifyAllRecords, 
   PermissionsViewAllRecords FROM ObjectPermissions 
 WHERE ParentId IN ( SELECT Id 
   FROM permissionset 
  WHERE PermissionSet.Profile.Name = 'System Administrator' )


2 comments:

  1. Hi,
    I'm using this query to get the object Level permissions -
    SELECT sObjectType, PermissionsCreate, PermissionsRead, PermissionsEdit, PermissionsDelete, PermissionsModifyAllRecords,
    PermissionsViewAllRecords FROM ObjectPermissions
    WHERE ParentId IN ( SELECT Id
    FROM permissionset
    WHERE PermissionSet.Profile.Name = 'System Administrator' )

    But its giving more than one objectPermissions for some of the standard objects, i.e. Account, Order.
    Is there any way to get only one objectPermssion for a specified profile and for a specified sObjectType?

    ReplyDelete
    Replies
    1. Use like below
      SELECT sObjectType, PermissionsCreate, PermissionsRead, PermissionsEdit, PermissionsDelete, PermissionsModifyAllRecords,
      PermissionsViewAllRecords FROM ObjectPermissions
      WHERE ParentId IN ( SELECT Id
      FROM permissionset
      WHERE PermissionSet.Profile.Name = 'System Administrator' ) AND sObjectType = 'Case'

      Delete