1

I am getting an error that I am not able to determine what is the main cause of it, what i am doing is creating a multipicklist into a checkboxes in a VF page. I am getting a weird error message when i try to submit my form:

error message:

Conversion Error setting value 'Travel and Adventure' for '#{selectedPerson_Interest}'.

this happens if i select 1 or more items

vf page code:

<apex:selectCheckboxes value="{!selectedPerson_Interest}" layout="lineDirection">
    <apex:selectOptions value="{!Person_Interest}" />
</apex:selectCheckboxes>  

controller:

public List<string> selectedPerson_Interest { get; set; }
public List<SelectOption> Person_Interest { 
    get {
        Person_Interest = new List<SelectOption>();
        Schema.DescribeFieldResult accountPerson_Interest = Account.Person_Interest__c.getDescribe();
        List<Schema.PicklistEntry> accountPerson_InterestValues = accountPerson_Interest.getPicklistValues();
        for (Schema.PicklistEntry a : accountPerson_InterestValues) {
            Person_Interest.add(new SelectOption(a.getLabel(), a.getValue()));
        }
        return Person_Interest;
    }
    set;
}   

i think my code looks pretty similar to: Displaying Multiselect Picklist as checkboxes question so i am not sure what i am doing wrong

EDIT:

So it works fine now, I am able to submit the form however I am not able to save the result into the field. This is the new code

public FormMiniFWCController() {
    selectedPerson_Interest = new List<string>();   
    selectedEmail_Subscriptions = new List<string>();

    Person_Interest = new List<SelectOption>();
    Schema.DescribeFieldResult accountPerson_Interest = Account.Person_Interest__c.getDescribe();
    List<Schema.PicklistEntry> accountPerson_InterestValues = accountPerson_Interest.getPicklistValues();
    for (Schema.PicklistEntry a : accountPerson_InterestValues) {
        Person_Interest.add(new SelectOption(a.getLabel(), a.getValue()));
    }
    Email_Subscriptions = new List<SelectOption>();
    Schema.DescribeFieldResult accountEmail_Subscriptions = Account.Email_Subscriptions__c.getDescribe();
    List<Schema.PicklistEntry> accountEmail_SubscriptionsValues = accountEmail_Subscriptions.getPicklistValues();
    for (Schema.PicklistEntry a : accountEmail_SubscriptionsValues) {
        Email_Subscriptions.add(new SelectOption(a.getLabel(), a.getValue()));
    }           
}

public String[] selectedEmail_Subscriptions { get; set; }
public SelectOption[] Email_Subscriptions { get; set; }
public String[] selectedPerson_Interest { get; set; }
public SelectOption[] Person_Interest { get; set; }

and this is the section where i am trying to save it:

Account acct = new Account(
    .......
    Person_Interest__c                = selectedPerson_Interest,
    Email_Subscriptions__c            = selectedEmail_Subscriptions
);
insert acct;

the error message that I get is Invalid initial expression type for field Account.Person_Interest__c, expecting: String

so i try to transform that list into a string and submitted however, if i go to the account and i try to modify the value, the value is save as a whole string and not as an options

3
  • Is it because your String list is not instantiated. public List<string> selectedPerson_Interest { get{selectedPerson_Interest=new List<string>() return selectedPerson_Interest;} set; } Commented Sep 3, 2014 at 5:30
  • Try initializing your selectedPerson_Interest in constructor as selectedPerson_Interest = new List<string>();
    – highfive
    Commented Sep 3, 2014 at 5:30
  • Thank you highfive, it does works however it saved wrongly on salesforce, as it saves all the option selected as 1 string, so i mean if i go to that record and click on edit i will see a long string instead of different options. The long string is because if i try to assign the variable into the field i was getting an error
    – manza
    Commented Sep 4, 2014 at 2:49

0

You must log in to answer this question.

Browse other questions tagged .