Loading

Conditionally render fields on Visualforce page based on picklist values

Udgivelsesdato: Oct 13, 2022
Beskrivelse
The following sample code provide an example as to how to render a Visualforce page based on a criteria
Løsning

Render a VF page based on a criteria

<apex:pageBlock id="xxxpb1">

<apex:pageBlockSection>
                    
<apex:actionRegion >               

  <apex:inputField id="xxxif1" value="{!Object.picklistfieldapiname1}" required="true" >

     <apex:actionSupport event="onchange" rerender="xxxpb1" />
  </apex:inputField>

</apex:actionRegion>
                 
</apex:pageBlockSection>
               
<apex:pageBlockSection id="xxxpbs1" rendered="true">

 <apex:inputField id="xxxif2" value="{!Object.Fieldtobedisplayed1}" rendered="{!IF(Object.picklistfieldapiname1 ='picklist value 1' || lead.Buyer_Type__c ='picklist value 2' ,true,false)}"/>

</apex:pageBlockSection>

<apex:pageBlockSection id="xxxpbs2" rendered="true">

  <apex:inputField id="xxxif3" value="{!Object.Fieldtobedisplayed2}" rendered="{!IF(Object.picklistfieldapiname1 ='picklist value 3' || lead.Buyer_Type__c ='picklist value 4' ,true,false)}"/>  
                                                                     
</apex:pageBlockSection>

</apex:PageBlock>

In the above code block, fields are displayed on VF page only if the rendering criteria is met.

Please note that this is a sample code and should be customized according to a business requirement.
Vidensartikelnummer

000385110

 
Indlæser
Salesforce Help | Article