0

I need to be able to filter leads and opportunities based on a partial or complete postcode. When this is entered I need the Leads and Opportunities to only contain the matching rows.

Page Layout

Visualforce page layout

Page Markup

        <apex:pageBlockSection title="Consumer" columns="1" collapsible="true">            
            <apex:outputPanel >
                <apex:outputLabel value="Postcode" for="consumerPostcode"/><br/>
                <apex:inputText id="consumerPostcode" value="{!consumerPostcode}" /><br/>
            </apex:outputPanel>
        </apex:pageBlockSection>
        <apex:pageBlockSection title="Leads with same Postcode" columns="1" collapsible="true">
            <apex:outputPanel >
                <apex:outputLabel value="Leads" for="consumerLeads"/><br/>
                <apex:inputText label="Open Leads" value="{!selectedLead}" list="{!openLeads}"/>                
            </apex:outputPanel>
        </apex:pageBlockSection>
        <apex:pageBlockSection title="Opportunities with same Postcode" columns="1" collapsible="true">
            <apex:outputPanel >
                <apex:outputLabel value="Opportunity" for="consumerOpportunities"/><br/>
                <apex:inputText label="Open Leads" value="{!selectedOpportunity}" list="{!openOpportunities}"/>
            </apex:outputPanel>
        </apex:pageBlockSection>

My controller contains two methods getOpenLeads() and getOpenOpportunities() which work as intended. However how can I trigger visualforce lists to update based on the value that is entered. These pre-fill on rendering and are never updated based on the value entered.

What is the idiomatic way to dynamically update a list on visualforce page?

1

There are 2 ways you can do this.

  1. The user can ender in the zip code and the page will automatically update with the open leads and the opportunities via ajax, and your table of results will refresh as the user enters in thier zip. I don't recommend this, because it could be very, very slow. What I do recommend is the next option
  2. The user can enter the zip code and click a button. That button calls getOpenLeads() and getOpenOpportunities() and displays them on the page in a say a table. In this approach, you can refresh just the results table. Try this:

        <apex:pageBlockSection title="Consumer" columns="1" collapsible="true">            
            <apex:outputPanel >
                <apex:outputLabel value="Postcode" for="consumerPostcode"/><br/>
                <apex:inputText id="consumerPostcode" value="{!consumerPostcode}" /><br/>
                <apex:commandButton value="Get Results"  action="{!getOppsAndLeads}" reRender="theLeads, theOpps"/>   
            </apex:outputPanel>
        </apex:pageBlockSection>

        <apex:pageBlockSection title="Leads with same Postcode" columns="1" collapsible="true" id="theLeads">
            <apex:outputPanel >
                <apex:outputLabel value="Leads" for="consumerLeads"/><br/>
                <apex:inputText label="Open Leads" value="{!selectedLead}" list="{!openLeads}"/>                
            </apex:outputPanel>
        </apex:pageBlockSection>
        <apex:pageBlockSection title="Opportunities with same Postcode" columns="1" collapsible="true" id="theOpps">
            <apex:outputPanel >
                <apex:outputLabel value="Opportunity" for="consumerOpportunities"/><br/>
                <apex:inputText label="Open Leads" value="{!selectedOpportunity}" list="{!openOpportunities}"/>
            </apex:outputPanel>
        </apex:pageBlockSection>

    </apex:form >
</apex:page>
  • Excellent, I could even skip the action and just let the rerender do the the work causing the existing getXXX to be called. – Martin of Hessle May 21 at 14:41

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.