1

Writing a VisualForce Page for Opportunity and having an issue with referencing the $UserRole.Id. It saves the way its written but its not doing what we need it to on the actual VisualForce Page. It is working for the $UserRole.Name tho :/ .

The code is as follows-

<apex:page Controller="CloseOppController">
  <apex:form>
    <apex:pageBlock title="Opportunity Close Form">
    <apex:pageMessages />
    <apex:pageBlockSection title="Win/Loss Detail" collapsible="false">
      <apex:inputField value="{!opportunity.StageName}" required="true"/>
      <br/>
      <apex:inputField value="{!opportunity.Closed_Reason__c}" required="{!IF($UserRole.Name != 'Sales Ops', true, false)}"/>
      <apex:inputField value="{!opportunity.Reason_Code__c}" required="{!IF($UserRole.Name != '***I have tried both the 15 digit and the 18 digit ID HERE***', true, false)}"/>
      <br/>
      <apex:inputField value="{!opportunity.Primary_Competitor__c}" required="{!IF($UserRole.Name != 'Sales Ops',true,false)}"/>
      <br/>
      <apex:inputField value="{!opportunity.Additional_Competitors__c}"/>
      <br/>

Thank you in advance!

closed as unclear what you're asking by Eric, crmprogdev, Ratan Paul, Alex Tennant, Vamsi Krishna Dec 13 '15 at 23:18

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • UserRole.Name is generally not an id. Have you tried querying the UserRole object through the workbench or dev console etc? I have also cleaned up your post a bit. In the future try and format your questions so they are easily read. :) – Jesse Milburn Dec 11 '15 at 20:29
  • Just fyi IF(boolean_expression, true, false) is always identical to simply boolean_expression. In other words, it is excessively verbose. – Adrian Larson Dec 11 '15 at 21:10
  • @JesseMilburn Sorry for the confusion... Yes, I am aware that UserRole.Name is not an ID... but the User's Role has an ID associated with it. ID is what I am trying to use instead of Name because we're more likely to change the "name" than the ID of the Role. When I use the UserRole.Name it does work and the field is not required for our Sales Ops folks... when I use the 15 or 18 digit ID of the "Sales Ops" Role it Saves but it doesnt work for either. This is the problem I am trying to solve. We want to use the ID instead of the Name... what am I doing wrong in the code that is not letting me? – Donald Bohrisch Dec 11 '15 at 21:13
  • @AdrianLarson , Can you please explain... I feel like there were some key words missing because I did not understand your statement? – Donald Bohrisch Dec 11 '15 at 21:14
  • I'm not sure I can state it more simply... you are evaluating a truthy expression and then saying if it is true, use true, and if it is false, use false. Just use the truthy value. – Adrian Larson Dec 11 '15 at 21:16