[SalesForce] Query on permission sets held by a user

Does anyone know a basic way that I can run a SOQL query to see which permission sets are attached to users?

We have a rather large issue where a button needs to be on a page layout for a few important users but the rest of the people on the profile should not have visibility or use of this.

I have pushed the idea to have a new profile, but my company is rather large and wont allow it… so I was going to use .js in a button to show the button to the users whom should be able to see it and hide hide it for those who should not be able to see it..

Other ideas are welcome 🙂

Best Answer

How PermissionSet relates to User is illustrated in this User, Sharing, and Permission Objects ERD.

So for example, this SOQL will list all permission set assignments:

select Assignee.Name, PermissionSet.Name
from PermissionSetAssignment
order by Assignee.Name, PermissionSet.Name

and this will list permission sets for a specific user:

select PermissionSet.Name
from PermissionSetAssignment
where Assignee.Id = :userId
order by PermissionSet.Name

You may wish to add further filtering.

Related Topic