function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Checking Role Hierarchy in Apex Class

Hi there,


I want to know if it's possible to check if the current user's Role is higher than another user's role through Apex. Is this possible? Thanks.




it can be done by some customization like creating a text field in the user "level". 

for example


role       level

VP         1

CEO     2

SE       3



so on a user record write a workflow  sot hat it populates the level field based on your criteria like if userrole is VP fieldupdate of level to 1.


then based in the levels of two users you can figure out whose role is higher.


Its just an idea you may face some problems but i think there should be no issues.



Hi Sanch,


In my case, I would to like to check logged user role with a role of particular record owner. If logged user role is on top of the record owner user role then I would like to show a visualforce page. any idea ?




Just in case as a reference I'm trying to accomplish same requirement and this post seems to provide hints to the solution,