function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sandra WicketSandra Wicket 

Add Filter to Visualforce Page

Hi there,
is it possible to add an Filter like Industry to a visualforce Page ? Here is my code 

Hi there , 
is it possible to add a Filter to the visualfoce page below? :

<apex:page controller="LeadPageControllerKontaktiert" tabStyle="Leads">
    
     <apex:pageBlock title="Meine Leads">
        <apex:pageBlockSection title="20 - kontaktiert" columns="1">
           
     
            <apex:pageBlockTable value="{!leads}" var="l" columnsWidth="60%, 20%, 20%">
                //columnsWidth="400px, 100px, 400px, 200px, 200px, 50px"                            
                <apex:column >
                                                               
                    <apex:facet name="header">Name</apex:facet>
                                                
                    <apex:outputLink value="/{!l.Id}" target="_blank">
                        <apex:outputField value="{!l.company}"/>
                    </apex:outputLink> 
                </apex:column>
 
                <apex:column value="{!l.Status}" />
                                    
                <apex:column value="{!l.Lead_Score__c}" />     
                       
                
            </apex:pageBlockTable>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>


Controller: 

public class LeadPageControllerKontaktiert {

    public List<Lead> getLeads() {       
        return [SELECT Id, Name, Company, Owner.name , Status, Lead_Score__c from Lead WHERE OwnerId = :UserInfo.getUserId() 
        AND Status = '20 - kontaktiert' AND LastModifiedDate != TODAY
        ORDER BY Lead_Score__c DESC 
        
        LIMIT 10
        ];
    }
}

Thanks for your help guys ! ;) 
Best Answer chosen by Sandra Wicket
Anil kumar GorantalaAnil kumar Gorantala
Ok here you go, 
leadpage (visualforce page code) :
<apex:page controller="LeadPageController" tabStyle="Lead">
    <apex:form>
        <apex:pageBlock title="Leads">
            <apex:pageBlockSection title="Leads Filtered by Industry" columns="1">
                Select Industry to Filter list:
                <apex:selectList size="1" value="{!industryPickvalue}">
                    <apex:actionSupport event="onchange" action="{!getleads}" rerender="table1"/>
                    <apex:selectOption itemLabel="Agriculture" itemValue="Agriculture" ></apex:selectOption>
                    <apex:selectOption itemLabel="Banking" itemValue="Banking" ></apex:selectOption>
                    <apex:selectOption itemLabel="Apparel" itemValue="Apparel"></apex:selectOption>
                </apex:selectList>
                <apex:pageBlockTable id="table1" value="{!leadList}" var="l" columnsWidth="60%, 20%, 20%">
                    //columnsWidth="400px, 100px, 400px, 200px, 200px, 50px"                            
                    <apex:column >
                        <apex:facet name="header">Name</apex:facet>
                        <apex:outputLink value="/{!l.Id}" target="_blank">
                            <apex:outputField value="{!l.company}"/>
                        </apex:outputLink> 
                    </apex:column>
                    <apex:column value="{!l.Status}" />
                    <apex:column value="{!l.industry}" />     
                </apex:pageBlockTable>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

leadpagecontroller class (apex code) :
 
public class LeadPageController {
    public string industryPickvalue{get; set;}
    public list<lead> leadList{get; set;}
    public void getLeads() {
        leadList = new list<lead>([SELECT Id, Name, Company, Owner.name , Status, Industry from Lead WHERE Industry =: industryPickvalue]);
    }
}

change it according to your values. I did it with standard values.

Please mark best answer if it solved your question.

All Answers

Anil kumar GorantalaAnil kumar Gorantala
add industry picklist on lead page. then get the value of the picklist into a property then use that property in Soql query in your return statement. reply if you have any queries.
Sandra WicketSandra Wicket
Thanks Anil, could you help me with that ? 
Anil kumar GorantalaAnil kumar Gorantala
Ok here you go, 
leadpage (visualforce page code) :
<apex:page controller="LeadPageController" tabStyle="Lead">
    <apex:form>
        <apex:pageBlock title="Leads">
            <apex:pageBlockSection title="Leads Filtered by Industry" columns="1">
                Select Industry to Filter list:
                <apex:selectList size="1" value="{!industryPickvalue}">
                    <apex:actionSupport event="onchange" action="{!getleads}" rerender="table1"/>
                    <apex:selectOption itemLabel="Agriculture" itemValue="Agriculture" ></apex:selectOption>
                    <apex:selectOption itemLabel="Banking" itemValue="Banking" ></apex:selectOption>
                    <apex:selectOption itemLabel="Apparel" itemValue="Apparel"></apex:selectOption>
                </apex:selectList>
                <apex:pageBlockTable id="table1" value="{!leadList}" var="l" columnsWidth="60%, 20%, 20%">
                    //columnsWidth="400px, 100px, 400px, 200px, 200px, 50px"                            
                    <apex:column >
                        <apex:facet name="header">Name</apex:facet>
                        <apex:outputLink value="/{!l.Id}" target="_blank">
                            <apex:outputField value="{!l.company}"/>
                        </apex:outputLink> 
                    </apex:column>
                    <apex:column value="{!l.Status}" />
                    <apex:column value="{!l.industry}" />     
                </apex:pageBlockTable>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

leadpagecontroller class (apex code) :
 
public class LeadPageController {
    public string industryPickvalue{get; set;}
    public list<lead> leadList{get; set;}
    public void getLeads() {
        leadList = new list<lead>([SELECT Id, Name, Company, Owner.name , Status, Industry from Lead WHERE Industry =: industryPickvalue]);
    }
}

change it according to your values. I did it with standard values.

Please mark best answer if it solved your question.
This was selected as the best answer
Sandra WicketSandra Wicket
Thanks ! 
Sandra WicketSandra Wicket
@anil kumar 
i need your help again ;) is it possible to show all leads  (itemValue=all ? )