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='testUser@ttest.com'

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='testUser@ttest.com' 

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.

  • 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) – sudhanshu Jun 14 at 7:47
  • But i am geeting some system permissions on this..How to avoid system permission Set to check – sudhanshu Jun 14 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. – Vijay Ganji Jun 14 at 8:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.