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
asadimasadim 

Checkboxes not saving

Hi,

 

I have a multiselect (Picklist) field in my object which I try to disply as a list of checkboxes using the following code inside the controller:

 

public List<SelectOption> Items { get { List<SelectOption> options = new List<SelectOption>(); Schema.DescribeFieldResult fieldResult = MyObj__c.Checklist__c.getDescribe(); List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues(); for( Schema.PicklistEntry f : ple) { options.add(new SelectOption(f.getLabel(), f.getValue())); } return options; } }

 

 Checklist__c is the aforementioned Picklist. Inside my VF page I have the following:

 

<apex:selectCheckboxes value="{!MyObj.Checklist__c}"> <apex:selectOptions value="{!Items}"/> </apex:selectCheckboxes >

 

 When I hit save I get an error that says Conversion Error setting value 'Option C Option D' for '#{MyObj.Checklist__c}'. My Picklist currently has the values Option A, B, C and D in it. Any ideas what I'm missing here?

Thanks in advance.

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Anand@SAASAnand@SAAS

You are trying to set the value of a multi select picklist from an "Array of Strings". Typically "select:checckboxes" expects an Array to set the selections into.

 

I would change to

 

<apex:selectCheckboxes value="{!ctlr.userSelections}"> <apex:selectOptions value="{!Items}"/></apex:selectCheckboxes >

 where ctlr.userSelections is a List<String> and a controller variable.  In the action method that you are calling, make sure you iterate through this list and set the value to the multi-select picklist (I think you need to separate them with a ';' e.g. Option 1;Option 2)

 

 

All Answers

Anand@SAASAnand@SAAS

You are trying to set the value of a multi select picklist from an "Array of Strings". Typically "select:checckboxes" expects an Array to set the selections into.

 

I would change to

 

<apex:selectCheckboxes value="{!ctlr.userSelections}"> <apex:selectOptions value="{!Items}"/></apex:selectCheckboxes >

 where ctlr.userSelections is a List<String> and a controller variable.  In the action method that you are calling, make sure you iterate through this list and set the value to the multi-select picklist (I think you need to separate them with a ';' e.g. Option 1;Option 2)

 

 

This was selected as the best answer
asadimasadim
EDIT: Thanks. That helped a lot. I ran into another issue, which was populating the checkboxes, but that's all fixed now.
Message Edited by asadim on 09-25-2009 12:08 PM
oorellanooorellano

Hi, do you have the fixed code?

Because I'm having the same problem and couldn't fix it.

 

Here is what I have on my page:

 

<apex:selectCheckboxes value="{!objectTypes}" layout="PageDirection">
        <apex:selectOptions value="{!objectTypesOptions}"/>
</apex:selectCheckboxes>

 

and on my controller objectsTypes is a List<String> and objectTypesOptions is a List<SelectOption>

 

Don't know what is wrong =S

 

Thanks,

Orlando