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
force shahidforce shahid 

How to do prefilling in multi select picklist field

 Hi friends,
When a page is loaded, I need multi-select picklist field should be prefilled with some value. Is it possible? 
Thanks in advance.

Thanks ,
Shahid.
Alain CabonAlain Cabon
Hi,

If you use <apex:inputfield> and <apex:outputfield>, the saved values of the multi-select picklist are easily shown.

The prefilled values are separated by semicolons ( ; ).
 
public class TestPage {
    public TestAll__c ta {get;set;}
    public PageReference pageButton () {
        system.debug('test:' + ta.picklist_multi__c);
        return null;
    }
    public TestPage() {
        ta = new TestAll__c();
        ta.picklist_multi__c = 'value1;value2;value5';  // prefilled values
    }
}
 
<apex:page controller="TestPage" >
    <apex:form>
        <apex:pageBlock>
            <apex:pageBlockButtons>              
                <apex:commandButton value="test" action="{!pagebutton}" />   
            </apex:pageBlockButtons>
            <apex:inputField id="test" value="{!ta.picklist_multi__c}" />      
        </apex:pageBlock>
    </apex:form>            
</apex:page>

Regards