Activity Forums Salesforce® Discussions How to render a VF page based on a criteria?

  • Prachi

    Member
    August 24, 2018 at 1:42 pm

    Hi Shradha,

    Here I am showing my code, hope this will help you:-

    Vf Page:-

    <apex:page controller="ifblog">
    <apex:form>
    <apex:commandButton action="{!allacc}" value="Show All Accounts" disabled="{!If((total<=acclimit),true,If((acclist.size>acclimit),true,false))}"/>
    <apex:dataTable value="{!acclist}" var="acc">
    <apex:column value="{!acc.id}" headerValue="Id"/>
    <apex:column value="{!acc.name}" headerValue="Name"/>
    </apex:dataTable>
    </apex:form>
    </apex:page>

    Controller:-

    public class iftest {
    public integer acclimit { get; set;}
    public integer total { get; set;}
    public list<account> acclist { get; set;}

    public iftest(){
    acclimit = 5;
    total = [select count() from account];
    acclist = [select id, name from account limit :acclimit];
    }

    public void allacc(){
    acclist = [select id, name from account];
    }
    }

    Thanks.

  • shariq

    Member
    September 19, 2018 at 12:37 am

    Hi,

    Try this -

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

    Hope this helps.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos