Play Games

Search This Blog

Monday, July 6, 2015

Search records based on picklist field(for eg:search lead records based on status filed)

Apex Class:
public class SearchLeads {
    public Lead newLead  {get;set;}
    public list<lead> leadList  {get;set;}
    public SearchLeads () {
        newLead = new Lead();
    }
    public list<lead> doSearch() {
        leadList =[select id,name,Status  from lead where status =: newLead.status];
        return null;
    }
}

Visualforce Page :
<apex:page controller="SearchLeads">
<apex:form >
Staus : <apex:inputField value="{!newLead.status}"/>
<apex:commandButton value="Search" action="{!doSearch}"/>
    <apex:pageBlock title="List of Leads">
        <apex:pageBlockTable value="{!leadList}" var="item">
            <apex:column value="{!item.name}"/>
            <apex:column value="{!item.status}"/>
        </apex:pageBlockTable>
   </apex:pageBlock>
</apex:form>
</apex:page>

output :