1

This is the scenario where users can mass update multiple records on a picklist field by clicking a button (code posted below):

  • User selects a few records on the Contact list view.
  • Then she clicks the custom Change Lead Source button added to the Conctact list view which takes her to a Visaulforce page where she can select a value from a picklist.
  • Once a picklist value is selected, she clicks the Change Lead Source button and comes back to the initial Contact list view. The leads she selected have changed their lead source value.

I would like to replicate this funcionality with a checkbox field instead of a picklist field. User should be able to select contacts on the list view, go to a Visualforce page where she can check or uncheck the field value, and then come back to the initial Contact list view.

What do I need to change in the Visualforcepage and Apex controller posted? Thank you!

<apex:form >
<apex:pageBlockSection columns="3" >
    <apex:commandbutton value="Change Lead Source" action="{!updatecontacts}"/>

    <apex:selectlist value="{!selected}" size="1">
        <apex:selectoptions value="{!options}"/>
    </apex:selectlist>
</apex:pageBlockSection>  
</apex:form>

</apex:pageBlock>

======================================================

public with sharing class massupdatefield{

    public List<Contact> contacts{get; set;}
    public list<selectoption> options{Get; set;}
    public string selected{get; set;}
    String saveUrl = ApexPages.currentPage().getParameters().get('retURL');

    public massupdatefield(apexpages.standardsetcontroller ssc){
        contacts = (list<contact>)ssc.getSelected();
        Schema.DescribeFieldResult FR = Contact.LeadSource.getDescribe();
        List<Schema.PicklistEntry> PL = FR.getPicklistValues();
        options = new list<selectoption>();
        for(schema.PickListEntry p:PL){
           options.add(new selectoption(p.getLabel(), p.getvalue()));
        }

    }

    public pagereference updatecontacts(){

        for(Contact c:contacts){
            c.LeadSource = selected;
        }
       update contacts;

        //return new pagereference(saveurl);
        pagereference pg = new pagereference('https://na15.salesforce.com/003/o');
        return pg;
    }
}
| improve this question | | | | |
  • This kinda sounds like you're just asking someone to do your work for you. You might want to ask a more specific question about how to accomplish your goal. Have you tried anything so far? Did you get caught up on some specific part? – Phil B Aug 14 '13 at 15:01
2

Instead of <apex:selectList> try <apex:selectCheckBoxes>.

The value for a selectCheckboxes needs to be a list<string> (just like if you had a multi-select selectList).

Example:

list<string> selected {get;set;}
| improve this answer | | | | |

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.