function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Saju NathSaju Nath 

how to populate the Values for the custom field picklist based on the selected value of Custom field Multi picklist

how to populate the Values for the custom field picklist based on the selected value of Custom field Multi picklist
Sumit Kumar Singh 9Sumit Kumar Singh 9
Hello Sanju, 
Is it Standard page or Custom Visualforce page? 
suresh sanneboina 4suresh sanneboina 4
hi Saju,

Please test the Below which might suits your requirement

Visualforce page:
<apex:page controller="MultiselectController">
    <apex:form >
        <apex:pageblock title="Contacts">
            <c:MultiselectPicklist leftlabel="Available Contacts" leftoption="{!allContacts}" rightlabel="Selected Contacts" rightoption="{!selectedContacts}" size="14" width="150px"></c:MultiselectPicklist>
            <apex:pageblockbuttons >
                <apex:commandbutton action="{!save}" value="Save"></apex:commandbutton>
            </apex:pageblockbuttons>
        </apex:pageblock>
        <apex:selectList value="{!customvalue}" label="date" multiselect="false" size="1" style="margin-right:0%">
              <apex:selectOptions value="{!dateList}" />                
        </apex:selectList> 
    </apex:form>
</apex:page>

Component
 
<apex:component controller="MultiselectController">
  <apex:attribute description="Label on left listbox." name="leftLabel" required="true" type="String"></apex:attribute>
  <apex:attribute description="Label on right listbox." name="rightLabel" required="true" type="String"></apex:attribute>
  <apex:attribute description="Size of listboxes." name="size" required="true" type="Integer"></apex:attribute>
  <apex:attribute description="Width of listboxes." name="width" required="true" type="String"></apex:attribute>
  <apex:attribute default="true" description="Should Up/Down buttons be displayed or not." name="showUpDownButtons" required="false" type="Boolean"></apex:attribute>
 
  <apex:attribute assignto="{!leftOptions}" description="Options list for left listbox." name="leftOption" required="true" type="SelectOption[]"></apex:attribute>
  <apex:attribute assignto="{!rightOptions}" description="Options list for right listbox." name="rightOption" required="true" type="SelectOption[]"></apex:attribute>
 
  <apex:outputpanel id="multiselectPanel" layout="block" styleclass="duelingListBox">
    <table class="layout">
      <tbody>
<tr>
          <td class="selectCell"><apex:outputpanel layout="block" styleclass="selectTitle">
              <!-- 
                Visualforce prepends the correct prefix to the outputLabel's 
                'for' attribute
              -->
              <apex:outputlabel for="multiselectPanel:leftList" value="{!leftLabel}"></apex:outputlabel>
            </apex:outputpanel>
             
            <select id="{!$Component.multiselectPanel}:leftList" class="multilist" multiple="multiple" size="0" style="width: {!width};">
              <apex:repeat value="{!leftOptions}" var="option">
                <option value="{!option.value}">{!option.label}</option>
              </apex:repeat>
            </select>
            
          </td>
          <td class="buttonCell"><apex:outputpanel layout="block" styleclass="text">Add</apex:outputpanel>
            <apex:outputpanel layout="block" styleclass="text">
              <apex:outputlink id="btnRight" value="javascript:moveSelectedOptions('{!$Component.multiselectPanel}:leftList', 
                  '{!$Component.multiselectPanel}:rightList', '{!$Component.leftHidden}', 
                  '{!$Component.rightHidden}');">
                <apex:image alt="Add" styleclass="rightArrowIcon" title="Add" value="/s.gif"></apex:image>
              </apex:outputlink>
            </apex:outputpanel>
            <apex:outputpanel layout="block" styleclass="text">
              <apex:outputlink id="btnLeft" value="javascript:moveSelectedOptions('{!$Component.multiselectPanel}:rightList', 
                  '{!$Component.multiselectPanel}:leftList', '{!$Component.rightHidden}', 
                  '{!$Component.leftHidden}');">
                <apex:image alt="Remove" styleclass="leftArrowIcon" title="Remove" value="/s.gif"></apex:image>
              </apex:outputlink>
            </apex:outputpanel>
            <apex:outputpanel layout="block" styleclass="duelingText">Remove</apex:outputpanel>
          </td>
          <td class="selectCell"><apex:outputpanel layout="block" styleclass="selectTitle">
              <apex:outputlabel for="multiselectPanel:rightList" value="{!rightLabel}"></apex:outputlabel>
            </apex:outputpanel>
            <select id="{!$Component.multiselectPanel}:rightList" class="multilist" multiple="multiple" size="0" style="width: {!width};">
              <apex:repeat value="{!rightOptions}" var="option">
                <option value="{!option.value}">{!option.label}</option>
              </apex:repeat>
            </select>
          </td>
          <td class="buttonCell"><apex:outputpanel layout="block" rendered="{!showUpDownButtons}" styleclass="text">Up</apex:outputpanel>
            <apex:outputpanel layout="block" rendered="{!showUpDownButtons}" styleclass="text">
              <apex:outputlink id="upBtn" value="javascript:slideSelectedOptionsUp('{!$Component.multiselectPanel}:rightList', 
                  '{!$Component.rightHidden}');">
                <apex:image alt="Up" styleclass="upArrowIcon" title="Up" value="/s.gif"></apex:image>
              </apex:outputlink>
            </apex:outputpanel>
            <apex:outputpanel layout="block" rendered="{!showUpDownButtons}" styleclass="text">
              <apex:outputlink id="downBtn" value="javascript:slideSelectedOptionsDown('{!$Component.multiselectPanel}:rightList', 
                  '{!$Component.rightHidden}');">
                <apex:image alt="Down" styleclass="downArrowIcon" title="Down" value="/s.gif"></apex:image>
              </apex:outputlink>
            </apex:outputpanel>
            <apex:outputpanel layout="block" rendered="{!showUpDownButtons}" styleclass="text">Down</apex:outputpanel>
          </td>
        </tr>
</tbody>
    </table>
<apex:inputhidden id="leftHidden" value="{!leftOptionsHidden}"></apex:inputhidden>
    <apex:inputhidden id="rightHidden" value="{!rightOptionsHidden}"></apex:inputhidden>
  </apex:outputpanel>
  <script type="text/javascript">
    if (!buildOutputString) {
      // Create a string from the content of a listbox
      var buildOutputString = function(listBox, hiddenInput) {
        var str = '';
 
        for ( var x = 0; x < listBox.options.length; x++) {
          str += encodeURIComponent(listBox.options[x].value) + '&'
              + encodeURIComponent(listBox.options[x].text) + '&';
        }
        str.length--;
 
        hiddenInput.value = str.slice(0, -1);
      }
    }
 
    if (!moveSelectedOptions) {
      // Move the selected options in the idFrom listbox to the idTo
      // listbox, updating the corresponding strings in idHdnFrom and
      // idHdnTo
      var moveSelectedOptions = function(idFrom, idTo, idHdnFrom, idHdnTo) {
        listFrom = document.getElementById(idFrom);
        listTo = document.getElementById(idTo);
 
        for ( var x = 0; x < listTo.options.length; x++) {
          listTo.options[x].selected = false;
        }
 
        for ( var x = 0; x < listFrom.options.length; x++) {
          if (listFrom.options[x].selected == true) {
            listTo.appendChild(listFrom.options[x]);
            x--;
          }
        }
 
        listTo.focus();
 
        buildOutputString(listFrom, document.getElementById(idHdnFrom));
        buildOutputString(listTo, document.getElementById(idHdnTo));
      }
    }
 
    if (!slideSelectedOptionsUp) {
      // Slide the selected options in the idList listbox up by one position,
      // updating the corresponding string in idHidden
      var slideSelectedOptionsUp = function(idList, idHidden) {
        listBox = document.getElementById(idList);
 
        var len = listBox.options.length;
 
        if (len > 0 && listBox.options[0].selected == true) {
          return;
        }
 
        for ( var x = 1; x < len; x++) {
          if (listBox.options[x].selected == true) {
            listBox.insertBefore(listBox.options[x],
                listBox.options[x - 1]);
          }
        }
 
        listBox.focus();
 
        buildOutputString(listBox, document.getElementById(idHidden));
      }
    }
 
    if (!slideSelectedOptionsDown) {
      // Slide the selected options in the idList listbox down by one position,
      // updating the corresponding string in idHidden
      var slideSelectedOptionsDown = function(idList, idHidden) {
        listBox = document.getElementById(idList);
 
        var len = listBox.options.length;
 
        if (len > 0 && listBox.options[len - 1].selected == true) {
          return;
        }
 
        for ( var x = listBox.options.length - 2; x >= 0; x--) {
          if (listBox.options[x].selected == true) {
            listBox.insertBefore(listBox.options[x + 1],
                listBox.options[x]);
          }
        }
 
        listBox.focus();
 
        buildOutputString(listBox, document.getElementById(idHidden));
      }
    }
     
    // initialize the string representations
    buildOutputString(document.getElementById('{!$Component.multiselectPanel}:leftList'), 
        document.getElementById('{!$Component.leftHidden}'));
    buildOutputString(document.getElementById('{!$Component.multiselectPanel}:rightList'), 
        document.getElementById('{!$Component.rightHidden}'));
  </script>
</apex:component>

Apex Class
 
public with sharing class MultiselectController {
    // SelectOption lists for public consumption
    public SelectOption[] leftOptions { get; set; }
    public SelectOption[] rightOptions { get; set; }
    public List<SelectOption> dateList{get;set;}
    public String customvalue {get;set;}
  
 public SelectOption[] selectedContacts { get; set; }
    public SelectOption[] allContacts { get; set; }
  
 public String message { get; set; }
  
 public MultiselectController() {
        selectedContacts = new List<SelectOption>();
         
        List<Contact> contacts = [SELECT Name, Id FROM Contact];    
        allContacts = new List<SelectOption>();
        for ( Contact c : contacts ) {
            allContacts.add(new SelectOption(c.Id, c.Name));
        }
    }
     
    // Parse &-separated values and labels from value and 
    // put them in option
    private void setOptions(SelectOption[] options, String value) {
        options.clear();
        String[] parts = value.split('&');
        for (Integer i=0; i<parts.size()/2; i++) {
            options.add(new SelectOption(EncodingUtil.urlDecode(parts[i*2], 'UTF-8'), 
              EncodingUtil.urlDecode(parts[(i*2)+1], 'UTF-8')));
        }
    }
     
    // Backing for hidden text field containing the options from the
    // left list
    public String leftOptionsHidden { get; set {
           leftOptionsHidden = value;
           setOptions(leftOptions, value);
        }
    }
     
    // Backing for hidden text field containing the options from the
    // right list
    public String rightOptionsHidden { get; set {
           rightOptionsHidden = value;
           setOptions(rightOptions, value);
        }
    }
  
 public PageReference save() {
        message = 'Selected Contacts: ';
        Boolean first = true;
        dateList =new List<SelectOption>();
        for ( SelectOption so : selectedContacts ) {
            if (!first) {
                message += ', ';
            }
            message += so.getLabel() + ' (' + so.getValue() + ')';
            dateList.add(new SelectOption(so.getLabel(),so.getLabel()));
            first = false;
        }
         
        return null;       
    }
}

 
Saju NathSaju Nath
Hello Sumit Kumar Singh,

Thanks for the Response. It is an Standard Page.
Sumit Kumar Singh 9Sumit Kumar Singh 9
Hello Sanju, 

As per salesforce docs, it's not possible.

"Multi-select picklists can be dependent picklists but not controlling fields".

Here, is the link to the doc - 
https://help.salesforce.com/apex/HTViewHelpDoc?id=fields_dependent_field_considerations.htm&language=nl (https://help.salesforce.com/apex/HTViewHelpDoc?id=fields_dependent_field_considerations.htm&language=nl)

Thanks, 
Sumit Kuamr SIngh
Long Quan PhamLong Quan Pham
@suresh sanneboina 4
Could you please share c:MultiselectPicklist 's code ?