+ Start a Discussion

Prepopulate values from apex in Multiselect picklist


I want to update picklist values in edit form based on values available in table.
My VF page looks like :
<apex:selectList value="{! Contact.assign_1_Business_Vertical__c }" multiselect="true" size="5">
                <apex:selectOptions value="{!parentPicklistOptions}"  />
                <apex:actionSupport event="onchange"  rerender="panel2,panel3" />
My controller is :
public List<SelectOption> getParentPicklistOptions() {
        List<SelectOption> selectOpts = new List<SelectOption>();
        for ( String s : parentDepMap.keySet() )
            selectOpts.add(new SelectOption(s, s));
          Contact.assign_1_Business_Vertical__c = 'Finance';
        return selectOpts;

I can only preset any one value as you can see from apex above where i selected 'Finance'.
I came to know from other forum topics that I can setup a getter setter for values variable of VF page in apex. and there the data type should be String array.
But in my case I am using standerd database field as Value variable in Vf page.
<apex:selectList value="{! Contact.assign_1_Business_Vertical__c }" multiselect="true" size="5">

How can I prepopulate multiple values in this scenario.

Naval Sharma4Naval Sharma4
If you are sending values with ';' separated then it will work without any problem.

For example - If you have 3 values which are Finance, Marketing and Sales and you want to Finance and Sales to be pre-selected then set the property as shown below.
Contact.assign_1_Business_Vertical__c = 'Finance;Sales';

Hope it helps.
No, It is not working.
When I do contact.assign_1_Business_Vertical__c = 'Finance';  // It works
BUT contact.assign_1_Business_Vertical__c = 'Finance;Automobile'; // Does not work for me.