Get the list of profiles having access to a specific object - SOQL Interview Question
Off-late a specific interview question has been asked in Salesforce Interviews a lot. That too especially when SOQL is concerned.
And the question goes like this, how can I get the list of profiles that has specific permission on a specific object?
The query goes like this!
In case you are interested in understanding how this works, continue reading.
Every profile will be associated with a Permission Set. Here is the visual confirmation for that.
The next part is, objects and their associated permissions are provided to us in the object ObjectPermissions
.
ObjectPermissions will have a foreign key called ParentId
which references the primary key in the object PermissionSet.
So the below query is going to give me a list of PermissionSet Id's
and associated permissions.
Now am gonna use this list and fetch all the profile's names from the PermissionSet
object by using the Id
field (primary key) in the WHERE
clause.
I know it can be overwhelming just by the looks of it.
Try to have a look at it a couple of times and then you will get to the bottom of it.
Hope this helps!
I have put together a FREE course on Javascript that helps you master Lightning Web Components.
It just takes 2 hours to finish the course and you will be able to feel the difference.