2

I have a requirement where I have to default selected all values on visual force page. I have searched everywhere but I still have no lead to work on it.

Would someone please advise how to do that using controller and visual force page please .

4
  • A multi-select choice field can have only one default value.
    – raym0nd
    Commented Apr 5, 2016 at 17:26
  • @raym0nd I understand that is standard salesforce, but can we not even achieve this using apex even?
    – Ricky
    Commented Apr 5, 2016 at 17:31
  • check my answer below
    – raym0nd
    Commented Apr 5, 2016 at 17:32
  • See Pre select multiple option in select option asked and answered in the last hour.
    – Keith C
    Commented Apr 5, 2016 at 17:44

1 Answer 1

0

In your page do something like

<apex:selectList size="5" id="selectRev" value="{!selValue}" multiselect="true" >
    <apex:selectOptions value="{!MultiValues}"/>
</apex:selectList>

Controller:

public List<SelectOption> getMultiValues() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('value1','value1'));
return options;
}


Public string[] getselValue(){
   //Where c.Test_Multi__c would be the name of the field you are storing the value in.

   if (c.Test_Multi__c!=null)
    return c.Test_Multi__c.split(';');

   else
     return null;
}

public void setselValue(string[] vals){
   c.Test_Multi__c=string.join(vals,';');
}
3
  • hey I was about to message here. I have implemented this code. But result is strange I only see one box of multiselect. Normally there are two box. One for Available and one for Choosen. But here I only see one box. Don't understand why ?
    – Ricky
    Commented Apr 5, 2016 at 19:38
  • also that is still not default selected all.
    – Ricky
    Commented Apr 5, 2016 at 20:02
  • 1
    raym0nd -- check out etiquette discussion on solicitation of marking answers as 'solutions'
    – cropredy
    Commented Apr 6, 2016 at 3:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .