0

In my apex code, i have a list of string stored in a LIST. I want to insert record and assign the List to a multiselect picklist field. Please Suggest.

String vals;
List<sObject> records = new List<sObject>([Select PicklistField__c from Object]);
for(sObject s : records ){
    vals = String.join(s.PicklistField__c , ';');
}

Gives me error

Method does not exist or incorrect signature: void join(String, String) from the type String

1
  • @adrian-larson I have Answered for updated question which is present now. As sfdcfox was answered for previous question before updating this question.
    – NITHESH K
    Sep 13, 2017 at 13:16

1 Answer 1

4

Just join the values with a semi-colon:

record.MultiSelectField__c = String.join(selectedValues,';');

Alternatively, you might consider binding the multi-select list directly to the field:

<apex:selectList multiple="true" value="{!record.MultiSelectField__c}">
   <apex:selectOptions value="{!availableOptions}" />
</apex:selectList>
2
  • @sfdfox No need to create a List of select option and assigning it ? directly will work ?
    – NITHESH K
    Sep 13, 2017 at 5:43
  • @NITHESHK Yes, presuming I've read the question correctly, it's just a normal String value, with the values separated by semi-colons, as demonstrated in the code I provided. You only need a list of SelectOption if you're going to use apex:selectOptions to render a list on the screen.
    – sfdcfox
    Sep 13, 2017 at 5:46

You must log in to answer this question.

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