apex:selectCheckboxes Command button stops working when an option is selected unless you click the button at least once before selecting any options

By | July 12, 2018

I have the following page:

<apex:page controller="testPageController">
    <apex:form>
        <apex:selectCheckboxes value="{!selectedContacts}">
            <apex:selectOptions value="{!contacts}" />
        </apex:selectCheckboxes>

        <apex:commandButton value="Test" action="{!testAction}" />
    </apex:form>
</apex:page>

Controller:

public class testPageController {
    public List<SelectOption> contacts {get; set;}

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

    public testPageController () {
        this.contacts = new List<SelectOption>();

        for (contact con : [
            SELECT Id, FirstName
            FROM Contact 
            LIMIT 10
        ]) {
            this.contacts.add(new SelectOption(con.Id, con.FirstName));
        }
    }

    public void testAction() {
        system.debug('Hello World!');
    }
}

Using apex version 43 in my developer org.

Steps to reproduce

  • preview page from dev console
  • select any number of options
  • click test
  • View Debug Logs

Expected

Hello World displays in logs

Actual

Nothing displayed in logs

Workaround

  • preview page from dev console
  • do not select any options
  • click test
  • View Debug Logs
  • Hello World displays
  • select any number of options
  • click test
  • View Debug Logs
  • Hello World displays

Can anyone reproduce this? Is this a bug or am I doing something wrong?