1

I have a VF page where you select some states. This is working but wanted to make the checkboxes using SLDS

Here is my controller code snippet:

public string superawesome;    
public String[] svalues { get; set; }
public SelectOption[] svalueList { get; set; }
    public reassignctrl(){
        for(Territory_Mapping__c record: [SELECT State_Name__c, State_Code__c from Territory_Mapping__c WHERE Country_Name__c = null ORDER BY State_Name__c ASC])
            svaluelist.add(new selectoption(record.State_Code__c, record.State_Name__c));     
        cvalueList = new SelectOption[0];
        cvalues = new String[0];
        for(Territory_Mapping__c record: [SELECT Country_Name__c, Country_Code__c from Territory_Mapping__c WHERE State_Name__c = null ORDER BY Country_Name__c ASC])
            cvaluelist.add(new selectoption(record.Country_Code__c, record.Country_Name__c));
    }
    superawesome = String.join(svalues, ',');
    blah blah}

The controller performs a search so it needs to return a list, Here is a snippet of that part

String userFilterQuery='';
        if(superawesome.contains('XX') && superawesome.contains('ZZ')){
            svalues.add('CA');
              userFilterQuery += ' AND (ShippingStateCode in: svalues OR ShippingCOuntryCode in: cvalues)'; 
        } 

And this works in my current VF Page:

<apex:selectCheckboxes value="{!svalues}"   id="checkedones">
      <apex:selectOptions value="{!svalueList}" />
</apex:selectCheckboxes>

But I have been trying to update it to this and I am not sure how to get the selected checkboxes back to the controller in a list. When I run the search I get this :

common.apex.runtime.impl.ExecutionException: Invalid conversion from runtime type String to List< String >

    <apex:inputHidden value="{!svalues}" id="st_opt"/>
           <fieldset class="slds-form-element">
               <legend class="slds-form-element__legend slds-form-element__label">States
                   <c:helpText helpText="Choose all States in the territory (to get All of CA, choose both Northern and Southern)"/></legend>
               <span class="slds-checkbox--faux"></span>
               <apex:pageBlockSection columns="8">
                   <div class="slds-form-element__control" >
                       <apex:inputCheckbox onclick="checkAllStates(this)" />
                       <apex:repeat value="{!svalueList}" var="opt">
                           <span class="slds-checkbox" >
                               <label class="slds-checkbox" >
                                   <input type="checkbox" data-value="{!opt.value}" id="checkedones" />
                                   <span class="slds-checkbox--faux"></span>
                                   <span class="slds-form-element__label" >{!opt.label}</span>
                               </label>
                           </span>
                       </apex:repeat>
                   </div>
               </apex:pageBlockSection>
                                    </fieldset>

I have been all over google trying to figure this out and I am sure I will facepalm when figured out.

I did change svalues to just a string, and tried adding onchange="document.getElementById('{!$Component.st_opt}').value = this.checked;" to the checkbox and the search would run but nothing was returned. So I get it has something to do with it being a list and I am not returning a list. But being an accidental programmer I am a little lost.

1
  • how are u populating cvalues list? also debug what comes out as userFilterQuery and see if the soql looks right to yuou
    – Rao
    Commented Dec 4, 2017 at 18:26

0

You must log in to answer this question.

Browse other questions tagged .