[SalesForce] Data in List to be assigned to multiselect picklist in apex

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

Best Answer

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>
Related Topic