I have a record that has a multiselect picklist field. I want to display on the VFP all of the different selections. When I load the page with the selectlist or selectcheckboxes, the values do not display.
I have tried both checkboxes and a standard picklist. How am I able to display the saved record values in the VFP? It looks like the values are being returned in a single string seperated by a semicolon ';'
<div class="slds-form-element slds-size--1-of-4">
<label class="slds-form-element__label" for="select-04">Suspicious Activity</label>
<div class="slds-form-element__control">
<apex:selectcheckboxes layout="pageDirection" value="{!selectedSuspiciousActivityOption}">
<apex:selectoptions value="{!suspiciousActivityOptions}" />
</apex:selectcheckboxes>
</div>
</div>
Debug displaying DB values of Suspicious_Activity__c field
10:37:10.0 (172238954)|USER_DEBUG|[44]|DEBUG|selectedSuspiciousActivityOption:: Banks: banks altered in some way;Business: business is not real
Is there a way around the dueling picklist? If there is not a simple way to just load the page with preexisting picklist data then my thought is I am going to have to split the Suspicious_Activity__c string by the ;
and use jQuery to check the appropriate boxes dependent on the values. Is there an easier way to just display on a multiselect picklist all of the selected options?
The picture shows that there should be two checkboxes checked (that data is already in the DB, we want to display this so the user can update later if they want to change the values)
Best Answer
<apex:selectList>
and<apex:selectCheckboxes>
both accept avalue
attribute binding whose data type isList<String>
. From the example for<apex:selectCheckboxes>
:Visualforce
Apex
If you wish to use
<apex:selectCheckboxes>
to display the value of your multi-select picklist, you'll need to add a property in your Apex controller typed as aList<String>
. Call it, say,checkboxSelections
:Then, your code (in Apex, not jQuery) can split the multi-select picklist's value on the semicolon delimiter (
;
) to populate that property.Upon performing a save, you'd need to re-join the list:
before performing DML.