+ Start a Discussion
Rocks_SFDCRocks_SFDC 

How to Display the user's list based on Permission

Hi Team,

I have a requirement where we just wanted to display the list of user's based on the permission we given.

Our input should be the permission name, then output should be the list of users those are having that permission.

Do we have any SOQL that supports this? or do we have any other workaround to display.

Thanks,
Anil



 
FearNoneFearNone
Hi rocks,

In fact, there is:
SELECT Id, IsOwnedByProfile, Label FROM PermissionSet
https://developer.salesforce.com/blogs/engineering/2012/06/using-soql-to-determine-your-users-permissions-2.html
 
Roshni RahulRoshni Rahul
Hi,

Suppose you want to Show all Users with ViewAllData Permission,
try this below SOQL,

SELECT Id, AssigneeId, Assignee.Name, PermissionSet.IsOwnedByProfile
FROM PermissionSetAssignment
WHERE PermissionSet.PermissionsViewAllData = True
ORDER BY PermissionSet.IsOwnedByProfile DESC, Assignee.Name

This query will return all Users with Permission to View All Data, either acquired from Profile or from Permission Set. So based on the permission you assign, to can query all the users.

Regards,
Roshni
Rocks_SFDCRocks_SFDC
Thank you, Roshni  and FearNone for your inputs.

For General Permissions and Administrative permissions at profile level, I'm writing the SOQL Query on the profile.

Now, how can I pass the variable as string immediate to after where condition in SOQL Query.

It is something like as follows:

Select Id, Name from Profile Where 'OurString' = true;
 
I have tried with Dynamic SOQL Query but it is giving an error. Please post if you have any sample queries like this.
 
Please help me out with the Query.
 
Thanks,
Anil
 





Roshni RahulRoshni Rahul
Hi,

Can you please post the dynamic SOQL that you have tried. let me check what went wrong.