function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SalesForceGirlSalesForceGirl 

Bug with apex:selectCheckboxes in Spring13

Right now it seems that anything with the <apex:selectCheckboxes> wont work (regardless of version since I did try bumping it back on both the page and controller). See blog entry for full debugging steps:http://salesforcegirl.blogspot.hu/2013/05/bug-with.html

when trying to use a repeat to populate the Lists via maps it fails as well for both<apex:selectCheckboxes> and <apex:selectList>. But if you do it the long way(like shown bellow), you can get<apex:selectList> to work at the very least, however not the <apex:selectCheckboxes> (which is what i need).

Here is the code:

public class sfg_testBugWithActionButton {

  public String fGrade {get; set;}
  public List<SelectOption> soGrade {get; set;}
  public String resultString {get; set;}

  public sfg_testBugWithActionButton() {
    createfilterMap();
    resultString = 'on Load of page';
  }

  public PageReference preformAction() {
    system.debug('Grade: ' + fGrade);//this wont be hit unless you use selectList
    resultString = 'button action preformed';
    return null;
  }

  private void createfilterMap() {
    soGrade = new List<SelectOption>();
    soGrade.add(new SelectOption('A', 'A'));
    soGrade.add(new SelectOption('B', 'B'));
    soGrade.add(new SelectOption('C', 'C'));
  }

}

Page:

<apex:page showHeader="true" sidebar="true" controller="sfg_testBugWithActionButton">
  <apex:form>
  <apex:outputpanel id="mainWrap">

    <h2>Grade</h2>
    <apex:selectCheckboxes value="{!fGrade}" layout="pageDirection">
      <apex:selectOptions value="{!soGrade}" />
    </apex:selectCheckboxes>

    <apex:commandButton action="{!preformAction}" rerender="renderWrap" value="Submit Action" />
    <br />

    <apex:outputpanel id="renderWrap">
      {!resultString}
    </apex:outputpanel>

  </apex:outputpanel>
  </apex:form>
</apex:page>
Best Answer chosen by Admin (Salesforce Developers) 
xnxn

The values in filterKeys are strings so {!filterKeys[key]} is a string, and <apex:selectCheckboxes> needs a list of strings as the value.  So if you change filterKeys to a map from strings to lists of strings, it should work.

fGender = new List<String>();
fGrade = new List<String>();
fRole = new List<String>();

filterKeys = new Map<String, List<String>> {
   'Gender' => fGender,
   'Grade' => fGrade,
   'Role' => fRole
};

All Answers

sushant sussushant sus
put these value in construtor
soGrade = new List<SelectOption>();
soGrade.add(new SelectOption('A', 'A'));
soGrade.add(new SelectOption('B', 'B'));
soGrade.add(new SelectOption('C', 'C'));
}
SalesForceGirlSalesForceGirl

nope, no joy. still doesnt work. Not to mention if it did that would still be broken functionallity since i am doing it in the constructor technically since the method that does it is being called by the constructor. 

SalesForceGirlSalesForceGirl

If you looked at the blog, you will see that it does work if you dont select a value, but once a value is selected it wont work.

Puja_mfsiPuja_mfsi

Hi,

Use the below code 

You need to get set the SelectCheckbox value because we can select muliple value in one time .

First declare the list of string and get set as below.

 

 

public class sfg_testBugWithActionButton {

List<String> fGrade = new List<String>();
public List<SelectOption> soGrade {get; set;}
public String resultString {get; set;}

public sfg_testBugWithActionButton() {
createfilterMap();
resultString = 'on Load of page';
}

public PageReference preformAction() {
system.debug('Grade: ' + fGrade);//this wont be hit unless you use selectList
resultString = 'button action preformed';
return null;
}

public List<String> getFGrade() {
return fGrade;
}

public void setFGrade(List<String> val) {
this.fGrade = val;
}

private void createfilterMap() {
soGrade = new List<SelectOption>();
soGrade.add(new SelectOption('A', 'A'));
soGrade.add(new SelectOption('B', 'B'));
soGrade.add(new SelectOption('C', 'C'));
}
}

 

 

SalesForceGirlSalesForceGirl

I am Get/Seting the fGrade

public String fGrade {get; set;}

even if i change it to 

public List<String> fGrade {get; set;}

it does not work. I even tried the long way like you suggested

private List<String> fGrade;

public List<String> getFGrade() {
return fGrade;
}

public void setFGrade(List<String> s) {
this.fGrade = s;
}

 

and still it does not work.

SalesForceGirlSalesForceGirl

I found a way to get the single example to work by initalizing the fGrade in the constructor, however this still doesnt work for the example with the map:

<apex:page showHeader="true" sidebar="true" controller="sfg_testBugWithActionButton">
 <apex:form>
    <apex:outputpanel id="mainWrap">
        <apex:repeat value="{!filterMap}" var="key">
          <h2>{!key}</h2>
          <apex:selectCheckboxes value="{!filterKeys[key]}" layout="pageDirection">
            <apex:selectOptions value="{!filterMap[key]}" />
          </apex:selectCheckboxes>
        </apex:repeat>
        <apex:commandButton action="{!preformAction}" rerender="renderWrap" value="Submit Action" />
      <apex:outputpanel id="renderWrap">
        {!resultString}
      </apex:outputpanel>
    </apex:outputpanel>
  </apex:form>
</apex:page>

 

public class sfg_testBugWithActionButton {
 
  public List<String> fGender {get; set;}
  public List<String> fGrade {get; set;}
  public List<String> fRole {get; set;}
 
  public String resultString {get; set;}

  public Map<String, List<SelectOption>> filterMap {get; set;}
  public Map<String, String> filterKeys {get; set;}

  public sfg_testBugWithActionButton() {
    //adding these makes it work with non map example
    fGender = new List<String>();
    fGrade = new List<String>();
    fRole = new List<String>();

    filterKeys = new Map<String, String> {
      'Gender' => 'fGender',
      'Grade' => 'fGrade',
      'Role' => 'fRole'
    };
    createfilterMap();
    resultString = 'on Load of page';
  }

  public PageReference preformAction() {
    resultString = 'button action preformed';
    return null;
  }

  private void createfilterMap() {
    filterMap = new Map<String, List<SelectOption>>();
    List<SelectOption> options = new List<SelectOption>();

    for (String s : filterKeys.keySet()) {
      if (s == 'Gender') {
        options = new List<SelectOption>();
        options.add(new SelectOption('Male', 'Male'));
        options.add(new SelectOption('Female', 'Female'));
        filterMap.put('Gender', options);
      }
      if (s == 'Grade') {
        options = new List<SelectOption>();
        options.add(new SelectOption('A', 'A'));
        options.add(new SelectOption('B', 'B'));
        options.add(new SelectOption('C', 'C'));
        filterMap.put('Grade', options);
      }
      if (s == 'Role') {
        options = new List<SelectOption>();
        options.add(new SelectOption('Support', 'Support'));
        options.add(new SelectOption('Sales', 'Sales'));
        options.add(new SelectOption('Marketing', 'Marketing'));
        filterMap.put('Role', options);
      } 
    }
  }
}

 

xnxn

The values in filterKeys are strings so {!filterKeys[key]} is a string, and <apex:selectCheckboxes> needs a list of strings as the value.  So if you change filterKeys to a map from strings to lists of strings, it should work.

fGender = new List<String>();
fGrade = new List<String>();
fRole = new List<String>();

filterKeys = new Map<String, List<String>> {
   'Gender' => fGender,
   'Grade' => fGrade,
   'Role' => fRole
};
This was selected as the best answer
SalesForceGirlSalesForceGirl

And it works! HAZA! 

 

 

your the best!