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 .

  • A multi-select choice field can have only one default value. – raym0nd Apr 5 '16 at 17:26
  • @raym0nd I understand that is standard salesforce, but can we not even achieve this using apex even? – Ricky Apr 5 '16 at 17:31
  • check my answer below – raym0nd Apr 5 '16 at 17:32
  • See Pre select multiple option in select option asked and answered in the last hour. – Keith C Apr 5 '16 at 17:44
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,';');
}
  • 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 Apr 5 '16 at 19:38
  • also that is still not default selected all. – Ricky Apr 5 '16 at 20:02
  • 1
    raym0nd -- check out etiquette discussion on solicitation of marking answers as 'solutions' – cropredy Apr 6 '16 at 3:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.