6

I have multiple sub role under each parent role.

Example

Minster
    Principal1
       Dean1
            Teacher1
            Teacher2...
       Dean2
            Teacher5...
       Dean3..
   Pricipal2...

I want to validate the current user is under Principal1.

I know we can get the UserRoleID in the formula. $UserRole.Id As there are many teachers under each Principal, it is impossible to check each user role Id including in the formula.

Is there any way that I can retrive the parent Role ID of current user, so that I can easily use it in the validation rule formula?

Or Is there any better idea to solve this kind of problem?

Please note that I am not writing code in APEX. I want to use in Validation Rule Formula of particular Object's field.

1 Answer 1

2

You should be able to get to this data in your validation rule using something like this:

if($UserRole.ParentRole.ParentRole.Id<>"TheIdYouWantToCompareTo", true, false)

You will be able to traverse up to 5 levels like this: $UserRole.ParentRole.ParentRole.ParentRole.ParentRole.ParentRoleId

6
  • That is not an option. You can do $UserRole, but it does not have a ParentRole field.
    – Mike Chale
    Nov 22, 2013 at 19:23
  • @MikeChale, not sure I understand. I just wrote a validation rule with this contents: if($UserRole.ParentRole.ParentRole.ParentRole.ParentRole.Name="ThisWorks", true, false). It saves fine - are you saying this doesn't work? Nov 22, 2013 at 19:34
  • When I put that in a validation rule in my sandbox and click "Check Syntax" it rejects it, saying the field ParentRole does not exist.
    – Mike Chale
    Nov 22, 2013 at 19:42
  • Interesting... Are you writing it exactly what I entered, along with the if, true and false pieces? What edition are you on? Nov 22, 2013 at 19:48
  • OK, I entered it wrong. Can you update your answer with the sample code?
    – Mike Chale
    Nov 22, 2013 at 19:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .