3

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.

4
  • 1
    Use apex:inputField for that, it will do that job automatically. Nov 11, 2013 at 12:04
  • I'm using select options wherein im querying all the contacts related to accounts. Please find VF column as below. It was working fine earlier though. It displays value properly but on insert it gets inserted within square brackets and comma.[value1,value2,value3] <apex:column headerValue="Contacts" rendered="true" > <apex:selectlist multiselect="true" value="{!t.Contacts__c}" rendered="true" id="contactcoln"> <apex:actionsupport event="onchange" reRender="selectedvalue" /> <apex:selectOptions value="{!con}" /> </apex:selectlist> </apex:column>
    – MEXI
    Nov 11, 2013 at 13:36
  • Take a look at this topic, it could help you Nov 11, 2013 at 13:47
  • Mast0r, .replace isnt helping me either. Since it isnt insertig values if i remove the square bracket. Is some thing wrong after the winter release ? I guess this was working fine before!
    – MEXI
    Nov 12, 2013 at 9:33

2 Answers 2

3

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.

2
  • I'll post an image that can give you a better understanding of my problem. The contacts field is the column with all the multiselect list of contacts. The selected contacts field shows how the selected data is getting inserted into the multipicklist field. I dont need the square brackets and comma. @ALL, please check this image i.stack.imgur.com/lWcDn.jpg
    – MEXI
    Nov 12, 2013 at 9:35
  • Thanks, I've taken a look at the image, it appears to be the same on as in your question though? I'm afraid there is no way to use apex:selectlist to bind directly to a picklist field, as I said in my answer you need to apply a wrapper class to convert to and from the picklist string value to a string list. This link given on one of the comments above is a good place to understand this process further, salesforce.stackexchange.com/questions/10727/… Nov 12, 2013 at 10:56
1

Multi-select picklists are not meant to store references to other objects. You should use a related list to do this. You may need to use a junction object.

2
  • What surprises me is that this was working fine some time back.
    – MEXI
    Nov 11, 2013 at 14:26
  • I'll post an image that can give you a better understanding of my problem. The contacts field is the column with all the multiselect list of contacts. The selected contacts field shows how the selected data is getting inserted into the multipicklist field. I dont need the square brackets and comma. @ALL, please check this image :i.stack.imgur.com/lWcDn.jpg
    – MEXI
    Nov 12, 2013 at 9:28

You must log in to answer this question.

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