0

Requirement-I need to sent true or false flag based on permissions assigned to user Permission sets. Suppose one user is having 5 permissions assigned to him/her ,I need to check(PermissionsConnectOrgToEnvironmentHub=true or PermissionsManageNetworks=true or PermissionsPackaging2=true) and if any permission is having any one of the permission i need to sent true flag else false i am not able to build a code to address this

SELECT Id, PermissionSet.Name,AssigneeId FROM PermissionSetAssignment WHERE Assignee.Username='[email protected]'

1 Answer 1

0

You can use the relationship query and query on PermissionSet Object which has all these permissions mentioned. You can query on PermissionSetAssignment and traverse to PermissionSet object and get the required results.

Your SOQL query should be something like below

SELECT AssigneeId,PermissionSetId,PermissionSet.PermissionsManageNetworks, PermissionSet.PermissionsConnectOrgToEnvironmentHub, PermissionSet.PermissionsPackaging2 FROM PermissionSetAssignment WHERE Assignee.Username='[email protected]' 

This below query will give you the records from Profile and PermissionSet

SELECT AssigneeId, permissionset.name, PermissionSetId FROM PermissionSetAssignment WHERE Assignee.FederationIdentifier='d866070' and (PermissionSet.PermissionsManageNetworks=true or PermissionSet.PermissionsConnectOrgToEnvironmentHub=true or PermissionSet.PermissionsPackaging2=true) 

There is a field called IsOwnedByProfile on PermissionSet which mention that the permission is provided at Profile level or PermissionSet level. Adding a additional check on the above query can get you the records only from Profile or only from PermissionSet. If you want only records of PermissionSet, get the records where IsOwnedByProfile is false, so your query would be

SELECT AssigneeId, permissionset.name, PermissionSetId FROM PermissionSetAssignment WHERE Assignee.FederationIdentifier='d866070' and (PermissionSet.PermissionsManageNetworks=true or PermissionSet.PermissionsConnectOrgToEnvironmentHub=true or PermissionSet.PermissionsPackaging2=true) and PermissionSet.IsOwnedByProfile = false 

You can refer the documentation on PermissionSet for further information.

3
  • Thaks for solution,based on above query I have prepared below query.......SELECT AssigneeId,permissionset.name,PermissionSetId FROM PermissionSetAssignment WHERE Assignee.FederationIdentifier='d866070' and (PermissionSet.PermissionsManageNetworks=true or PermissionSet.PermissionsConnectOrgToEnvironmentHub=true or PermissionSet.PermissionsPackaging2=true) Commented Jun 14, 2019 at 7:47
  • But i am geeting some system permissions on this..How to avoid system permission Set to check Commented Jun 14, 2019 at 7:48
  • Those are not system permissions, but those are the records which are owned by Profile, you can filter them using IsOwnedByProfile on PermissionSet object, Updated the answer with the same. That should help you. Commented Jun 14, 2019 at 8:06

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.