---
schema_version: "1"
id: 99c68f44d2396358e957c396881febc7b921e4c7facb7f727e92e59cf341dec4
title: Populating Dependent Picklist Values with Apex (Managed Package)
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/xcloud/264-0-0/os_populating_dependent_picklist_values_with_apex.md
canonical_url: https://help.salesforce.com/s/articleView?id=xcloud.os_populating_dependent_picklist_values_with_apex.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: d5a657bf7b9e1a4524ed059219a1aa1c0887bcc2eb3222cdf34dc07fdaa36b13
description: For the managed package runtime, you can populate Select, Multi-select, and Radio elements from a Callable implementation. The values for the element are obtained during the Omniscript's activation.
products:
  - Omnistudio
release: "264"
---
# Populating Dependent Picklist Values with Apex (Managed Package)

For the managed package runtime, you can populate Select, Multi-select, and Radio elements from a Callable implementation. The values for the element are obtained during the Omniscript's activation.

![Managed Package app icon](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-xcloud-omnistudio_for_managed_packages-264-0-0-production-enus/aa2554ec-624a-4ee6-8da4-6435670e6e62/resources-global/_corporate/images/managedpackageicon.png) This information is for Omnistudio for Managed Packages. For Omnistudio on standard runtime, see [Omnistudio Help](https://help.salesforce.com/s/articleView?id=xcloud.os_omnistudio_standard.htm&language=en_US).

When populating a Dependent Picklist through Apex, the returned Picklist Options are a **Map<String, List<Map<String, String>>**. The keys to the initial Map are the Language Independent ('name') options from the Controlling field. The List<Map> Options are 'Name' the Language Independent Option and 'Value' the UI Display value. For information on populating a picklist with no dependencies, see [Populating Picklist Values From Apex (Managed Package)](https://help.salesforce.com/s/articleView?id=xcloud.os_populating_picklist_values_from_apex.htm&release=264.0.0&type=5 "For the managed package runtime, you can populate Select, Multi-select, and Radio elements from an Apex class that implements Callable and Vlocity Open Interface. The values for the element are obtained during the Omniscript's activation.").

![image](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-xcloud-omnistudio_for_managed_packages-264-0-0-production-enus/aa2554ec-624a-4ee6-8da4-6435670e6e62/omnistudio_for_managed_packages/images/designerdependentelement.png)

Sample Apex Code:

```
global class PicklistPopulationExample implements Callable { 
    public Object call(String action, Map<String, Object> args) {
        Map<String, Object> input = (Map<String, Object>)args.get('input');
        Map<String, Object> output = (Map<String, Object>)args.get('output');
        Map<String, Object> options = (Map<String, Object>)args.get('options');
        return invokeMethod(action, input, output, options);
    }
    public Boolean invokeMethod(String methodName, Map < String, Object > input, Map < String, Object > outMap, Map < String, Object > options) {
        if (methodName.equals('PopulateDependentPicklist')) {
            PopulateDependentPicklist(input, outMap, options);
        }
        else if (methodName.equals('PopulatePicklist')) {
            PopulatePicklist(input, outMap, options);
        }
        return true;
    }
    
    // add the map under options to populate the picklist
    public void PopulatePicklist(Map<String, Object> input, Map<String, Object> outMap, Map<String, Object> options)
    {
        // hard coded list, these options could be results from a remote call/3rd party api
        List<Map<String,String>> picklist = new List<Map<String, String>>();

        Map<String, String> picklistOption = new Map<String, String>();
        picklistOption.put('name', 'Licensing & Permitting');
        picklistOption.put('value','Licensing & Permitting');
        picklist.add(picklistOption);
            
        picklistOption = new Map<String, String>();
        picklistOption.put('name', 'Contract');
        picklistOption.put('value','Contract');
        picklist.add(picklistOption);
        
        outMap.put('options', picklist);
    }
    
    // add the map of all possible picklists that will be chosen given the "controllingElement"
    // note that the "controllingElement" is an element name that gets passed in from omniscript
    public void PopulateDependentPicklist(Map<String, Object> input, Map<String, Object> outMap, Map<String, Object> options)
    {
        // Map of List where the Key is the Potential Values in the Other Picklist
        Map<String, List<Map<String, String>>> dependency = new Map<String, List<Map<String, String>>>();
                
        List<String> controlValList = new List<String>();
        // note that these are listed (above)
        controlValList.add('Licensing & Permitting');
        controlValList.add('Contract');

        // generating arbitrary entries for each of the above keys
        for(Integer i=0; i<2; i++)
        {
            List<Map<String, String>> optionList = new List<Map<String, String>>();

            for(Integer j=0; j<2; j++) {
                Map<String, String> tempMap = new Map<String, String>();
                tempMap.put('name', controlValList[i] + ' Child'); 
                tempMap.put('value', controlValList[i] + ' ChildV'); 

                optionList.add(tempMap);
            }
            dependency.put(controlValList[i], optionList);
        }
        
        outMap.put('dependency',dependency);
   }
    
    
}
```

The order of values from the Omniscript is the order of the output picklist.

![Note](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-xcloud-omnistudio_for_managed_packages-264-0-0-production-enus/aa2554ec-624a-4ee6-8da4-6435670e6e62/images/icon_note.png)

Note

Omniscript does not check to see if the dependent picklist value is valid when passed. Invalid values are discarded when the controlling picklist is changed.