I have a VF page that searches for contacts using the first name and mailing state of the contact. It then returns a list of contacts on that same page that match the search. I would like to be able to select a checkbox next to the returned records and be able to update the mailing state for all of the selected records. Here is what I have:

<apex:page controller="searchContacts_Controller">
<apex:form >
    <apex:pageBlock >
        <apex:pageBlockButtons location="top">
            <apex:commandButton value="Search" action="{!searchContacts}" reRender="contact-table" />

        <apex:pageBlockSection id="contact-table" columns="1">
            <apex:pageBlockSectionItem >
                <apex:outputLabel value="FirstName" />
                <apex:inputText value="{!Firstname}" />

            <apex:pageBlockSectionItem >
                <apex:outputLabel value="Mailing State" />
                <apex:inputText value="{!mailingState}" />

            <apex:pageBlockTable value="{!contacts}" var="c">

                <apex:column >
                    <apex:facet name="header">Name</apex:facet>

                <apex:column >
                    <apex:facet name="header">Mailing State</apex:facet>

public class searchContacts_Controller {
public List<Contact> contacts { get; set; }
public String Firstname { get; set; }
public String mailingState { get; set; }

public applyPayments_Controller()
    contacts = new List<Contact>();

public PageReference searchContacts()
    contacts = [select Id
                 from Contact 
                where FirstName = :Firstname
                and MailingState = :mailingState];
    return null;


Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.