[SalesForce] insert Multiselect values selected on Visualforce page

MY Page with the the picklist values under selectoptions column

Here is my problem.

I have made a visualforce page wherein a user select and account and once the account is selected, another field populates all the related contacts.

Once the user selects multiple contacts and clicks save, the values need to be inserted into the custom multiselect picklist field.

However when I select multiple values, the value that gets inserted is a single string with square brackets and comma.
I am not able to replace or split either.

Best Answer

You cannot bind a SObject field (even a picklist one) to a standard apex:selectList component...

<apex:page standardController="Test__c">
    <apex:form >
        <apex:selectlist multiselect="true" value="{!Test__c.Colours__c}"/>
        <apex:inputField value="{!Test__c.Colours__c}"/>
    </apex:form>
</apex:page>

enter image description here

The documentation for the apex:select says this about the value attribute.

A merge field that references the controller class variable that is associated with this selectList. For example, if the name of the associated variable in the controller class is myListSelections, use value="{!myListSelections}" to reference the variable. If multiselect is true, the value attribute must be of type String[] or a List of strings. Otherwise, it must be of type String.

A custom field of type multi picklist is exposed as a String (semi colon delimited), I'm not sure how this ever worked in a read or write case for you to be honest. If you switch to use apex:inputField it will work, though i imagine the appearance is not what you want? Your only option is to implement a wrapper class and expose a true String[] array or list as per the requirements of the apex:selectList component above.