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>
3

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.

  • I did the change but its not working for me. – sfdc Dec 13 '15 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. – Kiran Machhewar Dec 13 '15 at 4:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.