0

When changing a multiselect field I am calling a updateLOBlist() method to update a string (multiSelectValues.) However, when deselecting values from the multiselect I am not seeing the string values change. In this example I originally had selected AH, CommercialAuto, GeneralLiability, Homeowners, NonStandardAuto, PersonalAuto but when deselecting the string does not change.

enter image description here

Debug after removing items: AH, CommercialAuto, NonStandardAuto, PersonalAuto

DEBUG|UPDATED LOBS {AH, CommercialAuto, GeneralLiability, Homeowners, NonStandardAuto, PersonalAuto}
DEBUG|LOB FOUND NONSTDAUTO 


  public Set<String> multiselectValues = new Set<String>();

    Public Void updateLOBlist() {                  
     multiSelectValues.addAll(CCRA.Lines_of_Business__c.split(';'));
      System.debug('UPDATED LOBS ' + multiSelectValues);           
     if(multiSelectValues.contains('NonStandardAuto')){
      System.debug('LOB FOUND NONSTDAUTO ');
     }else {
      System.debug('NO LOB FOUND');
     }
    }

Visualforce Page with Multiselect

<apex:pageBlockSectionItem dataStyleClass="col"  >
<apex:actionRegion >                      
 <apex:inputField id="LOB" value="{!Claims_Client_Risk_Assessment__c.Lines_of_Business__c}" styleClass="col2" >
  <apex:actionSupport action="{!updateLOBlist}" event="onchange" reRender="theLOBTabPanel,OutputLOBTabPanel,theLOBTabPanel1" / > 
 </apex:inputField>
</apex:actionRegion>                     

1 Answer 1

3

When your action method executes, you add into the set multiSelectValues the current values of field CCRA.Lines_of_Business__c but ...

you never reset the collection multiSelectValues to empty and hence previous values are still there!

public Set<String> multiselectValues = new Set<String>();

 public Void updateLOBlist() {                  
  multiselectValues.clear();
  multiSelectValues.addAll(CCRA.Lines_of_Business__c.split(';'));

 }
2
  • Excellent @cropredy ! Hasty oversight on my part!
    – rickmac
    Jul 28, 2018 at 1:09
  • cool; as favor to community, if that works out for you; mark the answer as 'accepted' or post a better answer
    – cropredy
    Jul 28, 2018 at 1:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .