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
SFDC_SaurabhSFDC_Saurabh 

Prepopulate values from apex in Multiselect picklist

Hello,

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" />
            </apex:selectList>
My controller is :
public List<SelectOption> getParentPicklistOptions() {
        List<SelectOption> selectOpts = new List<SelectOption>();
        for ( String s : parentDepMap.keySet() )
            selectOpts.add(new SelectOption(s, s));
      System.debug(contact.assign_1_Business_Vertical__c);
          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.
SFDC_SaurabhSFDC_Saurabh
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.
Zachary Alexander 22Zachary Alexander 22
Answer found here -- THE FIELD ONLY ACCEPTS LIST<STRING> FOR INPUTS!
https://developer.salesforce.com/forums/?id=906F0000000g28uIAA

You need to convert 'Finance;Automatible' into the following:

List<String> valueList = List<String>();
valueList .add('Finance');
valueList .add('Automatible');

Then you can feed valueList into the multi-select and it will show the pre-populated values! Ack!