- Salesforce Development Posts of a Fashion by Matt Lacey

Back to Posts

Multi-Selection VisualForce selectLists

A fellow dev was having an issue with these, he was getting a strange error when trying to submit a form which included two such lists about not being able to save the values to the controller variables specified.

It turned out the problem was that in the controller he had a member variable defined as follows:

String m_strArray [] {get; set;}

And that was what he was using m_strArray for the value parameter of the <apex:selectlist>. The problem is that the select list doesn't create a string array, it simply writes to the one specified - so in this case it didn't have one to write to. The problem was simply solved by creating the array instance in the constructor for the controller:

m_strArray = new String[]{};