0

I want to render Account.Type and Account.Industry when Account.Rating ='Hot'

  <apex:page standardController="Account">
  <apex:form >
  <apex:pageBlock title="Account Edit" id="pb">
  <apex:pageblockSection title="Account Information" collapsible="false" columns="2" id="pbs1">
   <apex:inputField value="{!Account.Name}"/>
   <apex:inputField value="{!Account.Rating}">
   <apex:actionSupport event="onchange" rerender="op1"/>  
   </apex:inputField>
    <apex:outputPanel id="op1"  layout="none"> 
   <apex:outputPanel rendered="{If(!Account.Rating == 'Hot',true,false)}" id="op2">
   <apex:inputField value="{!Account.Type}"/>
   <apex:inputField value="{!Account.Industry}"/>
   </apex:outputPanel> 
   </apex:outputPanel> 
  </apex:pageblockSection>
  <apex:pageBlockButtons >
  <apex:commandButton action="{!Save}" value="Save"/>
  <apex:commandButton action="{!Cancel}" value="Cancel"/>
  </apex:pageBlockButtons>
  </apex:pageBlock>
 </apex:form> 
</apex:page>

1 Answer 1

4

There were two problems: You need to wrap rating in actionRegion since Account name is mandatory. Also you have placed ! at wrong place in redered condition. I have made corrections. Please check below code snippet.

<apex:page standardController="Account">
  <apex:form >
  <apex:pageBlock title="Account Edit" id="pb">
  <apex:pageblockSection title="Account Information" collapsible="false" columns="2" id="pbs1">
   <apex:inputField value="{!Account.Name}"/>
   <apex:actionRegion>
       <apex:inputField value="{!Account.Rating}">
       <apex:actionSupport event="onchange" action="{!null}" rerender="op1"/>  
       </apex:inputField>
   </apex:actionRegion>
    <apex:outputPanel id="op1" > 
       <apex:outputPanel rendered="{!If(Account.Rating == 'Hot',true,false)}" id="op2">
           <apex:inputField value="{!Account.Type}"/>
           <apex:inputField value="{!Account.Industry}"/>
       </apex:outputPanel> 
   </apex:outputPanel> 
  </apex:pageblockSection>
  <apex:pageBlockButtons >
  <apex:commandButton action="{!Save}" value="Save"/>
  <apex:commandButton action="{!Cancel}" value="Cancel"/>
  </apex:pageBlockButtons>
  </apex:pageBlock>
 </apex:form> 
</apex:page>

Before changing rating: enter image description here After changing rating to Hot: enter image description here I hope this helps you.

2
  • I did the change but its not working for me.
    – sfdc
    Commented Dec 13, 2015 at 4:20
  • @sfdc will you please recheck, i have tried this on dev org and attached snapshots. Do one thing try to just copy paste above code. I think while modifying your code something should have left. Then after that you can compare. Let me know if you face any issue. Commented Dec 13, 2015 at 4:25

You must log in to answer this question.

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