You need to sign in to do that
Don't have an account?
AnkitAgarwalSF
How to add controlling and dependent picklist values in apex test class
I have written apex code to get the controlling field values and corresponding field values but to test that I need to add some values in both controlling and dependent fields and map them in the test class. Most of the posts tell how to get get the mapped values but they dont say how to add the values and map them.
http://mysalesforceescapade.blogspot.in/2015/03/getting-dependent-picklist-values-from.html
Having a Util method for scenario like these will help you get the Controlling and Dependent values in Apex.
Regarding Test class:
PicklistEntry falls in definition Metadata type thus may not be created from Apex. Ideally you should refer to existing fields to test your class.
@isTest public class PicklistFieldControllerTest {
PicklistFieldController controller = new PicklistFieldController();
Map<String,List<String>> valueMap = controller.getDependentOptionsImpl('Account','ShippingCountryCode','ShippingStateCode');
System.debug('DEPENDENT VALUES ... : ' + valueMap.get(contr));