1

Im quite new to salesforce..need a little help.

i want to create a custom picklist in VF page, and then according to the value selected want to render a pageblocktable below on pressing a command button. This is my code snippet.

 <apex:commandButton value="Filter" />
   <apex:selectList multiselect="false" size="1">
                <apex:selectOption itemValue="Qualification" itemLabel="Qualification"/>
                <apex:selectOption itemValue="Closed Won" itemLabel="Closed Won"/>
                <apex:selectOption itemValue="Closed Lost" itemLabel="Closed Lost"/>
            </apex:selectList>
  <apex:pageBlock >
<apex:pageBlockTable value="{!OppList2}" var="op2" title="Opportunities">

  <apex:column value="{!op2.name}"/>
  <apex:column value="{!op2.Accountid}"/>
  <apex:column value="{!op2.CloseDate}"/>
   <apex:column value="{!op2.Ownerid}"/>
  <apex:column value="{!op2.Probability}"/>
  </apex:pageBlockTable>
  </apex:pageBlock>

controller:

public class Opp {


public List<Opportunity> OppList2{get; set;}

string searchquery='select name,accountid,ownerid,closedate,Probability from Opportunity ';

public Opp(){

OppList2=Database.query(searchquery);

}
}

Please help.

0
0

Please find the updated code as below. I have used <apex:actionSupport tag to pass the picklist value onchange event. <apex:actionStatus is used to provide hint to the user that something is going on in the backend. Hope this will help.

VF Page

<apex:page controller="Opp">
  <apex:form>
    <apex:outputLabel value="Qualification  :  " for="stagename"/>
    <apex:selectList multiselect="false" value="{!filter}" label="Qualification" size="1" id="stagename">
      <apex:selectOption itemValue="" itemLabel="--Select--"/>
      <apex:selectOption itemValue="Closed Won" itemLabel="Closed Won"/>
      <apex:selectOption itemValue="Closed Lost" itemLabel="Closed Lost"/>
      <apex:actionSupport event="onchange" reRender="pgbtable" action="{!getresult}" status="status"/>
    </apex:selectList>
    <apex:actionStatus id="status">
      <apex:facet name="start">
        <div>Loading Please wait........</div>
      </apex:facet>
    </apex:actionStatus>
    <apex:pageBlock >
      <apex:pageBlockTable value="{!OppList2}" var="op2" title="Opportunities" id="pgbtable">
        <apex:column value="{!op2.name}"/>
        <apex:column value="{!op2.Accountid}"/>
        <apex:column value="{!op2.CloseDate}"/>
        <apex:column value="{!op2.Ownerid}"/>
        <apex:column value="{!op2.Probability}"/>
      </apex:pageBlockTable>
    </apex:pageBlock>
  </apex:form>
</apex:page>

Controller

public class Opp {
    public String filter{get; set;}
    public List < Opportunity > OppList2 {
        get;
        set;
    }

    string searchquery = 'select name,accountid,ownerid,closedate,Probability from Opportunity ';

    public Opp() {
        OppList2 = Database.query(searchquery);
    }
    public void getresult() {
        searchquery = 'select name,accountid,ownerid,closedate,Probability from Opportunity where StageName = :filter ';
        OppList2 = Database.query(searchquery);
    }
}
1
  • The given answer is working fine. Thanx for ur help. +1 :) – Shri Aug 11 '15 at 7:02

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.