3

I have a custom ListView button and I'm trying to update a multi-select list field.

Here is my VF page:

<apex:page standardController="Lead" extensions="LeadListViewMassUpdateControllerExt" recordSetVar="Leads">
<apex:form id="theForm">
<apex:pageBlock title="Lead Source Mass-Update" mode="edit" id="theBlock">
    <apex:pageMessages />
    <apex:pageBlockSection id="mus1">
        <apex:inputField value="{!lead.Solution_Interest_s__c}" id="source">
            <apex:actionSupport event="onchange" rerender="selectedlist" />
        </apex:inputField>
    </apex:pageBlockSection>
    <apex:pageBlockButtons location="bottom" id="mubut">
        <apex:commandButton value="Save" action="{!save}" id="btnSave"/>
        <apex:commandButton value="Cancel" action="{!cancel}" id="btnCancel"/>
    </apex:pageBlockButtons>
</apex:pageBlock>
<apex:pageBlock title="Selected Leads" id="selectedlist">
    <apex:pageBlockTable value="{!selected}" var="l" id="theTable">
        <apex:column value="{!l.name}" id="leadname"/>
        <apex:column value="{!l.Solution_Interest_s__c}" id="solutionInterest" />
    </apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

Here is my controller:

public class LeadListViewMassUpdateControllerExt {

ApexPages.StandardSetController setCtrl;

public LeadListViewMassUpdateControllerExt(ApexPages.StandardSetController controller) {
setCtrl = controller;
if(setCtrl.getSelected().size() == 0) 
ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.warning, 'No records were selected. Please go back and select records to be updated'));
}

}

This code will replace the existing values in the multi-select list field. Instead, I'd like to add new values to multi-select list that already exist? I want to add and NOT replace values.

The issue is I need to the user to add a solution interest value to the records. For example, a lead record has the values: "A" and "B" for solution interest. I want the user to be able to select "C" from the multiple select list and save the record. Then the lead record will have the values "A", "B" and "C" for solution interest. Currently, the code replaces "A" and "B" with "C".

Thanks for any help.

  • 1
    Where is a multiselect list in your code? – Sergej Utko Jun 25 '14 at 13:26
  • It is the input field Solution_Interest_s__c. Using the standard input field component displays the multi-select list. – Dman100 Jun 25 '14 at 13:55
1

The code below will get all the current picklist values from the Solution_Interest_s__c and also add one more value called My Label

public List<SelectOption> solutionInterestOptions {
    get {
        if (solutionInterestOptions == null) {
            solutionInterestOptions = new List<SelectOption>();
            Schema.DescribeFieldResult r = Lead.Solution_Interest_s__c.getDescribe();
            for (Schema.PicklistEntry pr : r.getPicklistValues()) {
                solutionInterestOptions.add(new SelectOption(pr.getValue(), pr.getLabel()));
            }

            // Do this as many times as needed
            solutionInterestOptions.add(new SelectOption('MyValue', 'My Label'));
        }
        return solutionInterestOptions;
    }
    set;
}

You can access the solutionInterestOptions in the VF page as follows:

<apex:pageBlockSectionItem >
    <apex:outputLabel value="Solution Interest"/>
    <apex:selectList value="{!lead.Solution_Interest_s__c}">
        <apex:selectOptions value="{!solutionInterestOptions}"/>
    </apex:selectList> 
</apex:pageBlockSectionItem>
| improve this answer | |
  • Correct me if I'm misunderstanding, but I'm referring to a multi-select list. So, in my original code, I want to be able to add additional values to the values that already exist in each record of the multi-select list and then update. Right now, the code will simply replace the values and update. – Dman100 Jun 25 '14 at 14:12
  • Do you mean in the UI you want to select more than one value in the available list? – BarCotter Jun 25 '14 at 14:32
  • In the UI, the multi-select list displays correctly with all the values defined. The issue is I need to the user to add a solution interest value to the records. For example, a lead record has the values: "A" and "B" for solution interest. I want the user to be able to select "C" from the multiple select list and save the record. Then the lead record will have the values "A", "B" and "C" for solution interest. Currently, the code replaces "A" and "B" with "C". Does that help explain? – Dman100 Jun 25 '14 at 14:43
  • You should update your question with that information and possibly screenshots as well – BarCotter Jun 25 '14 at 14:59
  • Updated my original post. Any further thoughts on this? – Dman100 Jun 25 '14 at 15:10

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.