How to Use Profle/Role Name in a Rendering Condition using the Running User Attributes

  • 1
  • Question
  • Updated 9 months ago
  • Answered
I have not been able to get this to work and am hoping there is a simple solution to this that I am missing. I am trying to show certain components (fields, tabs etc..) based on the running users Profile/Role Name. I tried the below and it is not working. I need to use name because of ID differences between environments. I don't really want to have a entire page copy for a different profile as I only have a couple pieces that need to render based on User Role.

How can I achieve this?

Photo of Jarrod Hinson

Jarrod Hinson

  • 2,310 Points 2k badge 2x thumb

Posted 4 years ago

  • 1
Photo of Jarrod Hinson

Jarrod Hinson

  • 2,310 Points 2k badge 2x thumb
I tried adding a formula field to the User object to get the Role > Name. But the field is not available for use in the Rendering statement list for Running User Attributes.
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb
It's probably not working because Role Id is a Salesforce Id and not text. I always make a model called RunningUser on the user object like so, and use it for rendering stuff :

Photo of Jarrod Hinson

Jarrod Hinson

  • 2,310 Points 2k badge 2x thumb
Ah ok, I was kind of thinking it had the model there already since the conditions allow to use that small set of user properties. Makes sense though to just go get the entire user model.
Photo of Joyson   Tuscano

Joyson Tuscano

  • 144 Points 100 badge 2x thumb
Hi Moshe,

        My Scenario :
        I want to display the  list of all the users from specific Profile For Example (Sales Profile)
        
        Problem :
        It is works fine with  System Administrator profile but it does not work for Sales Profile 



Thanks In Advance !!
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,026 Points 20k badge 2x thumb
Most likely that profile does not have access to the profile object.  Do they have the "view setup and configuration" system permission? 
Photo of Joyson   Tuscano

Joyson Tuscano

  • 144 Points 100 badge 2x thumb
Hi Rob.

I have enable " view setup and configuration" system permission for Sales user and my filter condition works as expected.

It also enable set up option as well.

Is there any way to remove set up option for sales profile

Photo of Zach McElrath

Zach McElrath, Employee

  • 49,242 Points 20k badge 2x thumb
When you say "Id differences between environments", are you building a managed package, or just dealing with moving between Sandboxes tied to one Production org? If the latter, then the Ids for Profiles, Users, and Roles don't change between Sandboxes / Production as long as they're Sandboxes of the same Production org --- the Ids are consistent.

However, if you're building a managed package, OR if you just don't want to deal with Ids and would rather deal with Names, then Moshe's approach is the recommended one:

1. Create Formula Field(s) on the User object called "Profile Name" or "User Role Name", whose formula values are "Profile.Name" and "UserRole.Name", as needed. These are necessary because for some reason, standard users do not have access to the Profile.Name field (even for their own Profile!) directly via a Model on the User object --- very annoying. But Formula Fields circumvent this limitation --- any user will be able to see the Name of their Profile or Role if you create a Formula Field for this purpose.
2. Create a Model on the User object called "RunningUser" or something like that, with a Condition on it limiting the Model to return just the user record for the running user. Request your custom "Profile Name" and/or "User Role Name" formula fields.
3. IN your Rendering Conditions, have the Source Type be "Model field value" rather than Running user attribute, and point it at the RunningUser Model, and at the User Role Name or Profile Name fields.
Photo of Sarah Hughes

Sarah Hughes

  • 454 Points 250 badge 2x thumb
Zach, I just followed your instructions and still can't get this to work. It is something I actually gave up on awhile ago and am coming back to...

I am testing it out on a button, but need to use the solution in about a million other places.

Am I missing something?
(Edited)
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,026 Points 20k badge 2x thumb
Sarah.  Can you maybe send us an email (support at skuidify dot com) with a more detailed description of what you are trying to do and what is happening with it?

We want to take care of you....  
Photo of Sarah Hughes

Sarah Hughes

  • 454 Points 250 badge 2x thumb
Will do.