We are implementing the DependentPicklists class found in another answer on this site. Our org has State and Country picklists enabled, so we are trying to get this to work using the Contact.MailingCountry
and Contact.MailingState
fields.
Once I get this to work, I plan to return the result via @AuraEnabled
method.
Here's how I'm mocking it up:
String stateString = 'Contact.MailingState';
List<String> splitStateString = stateString.split('\\.');
Schema.SobjectField stateField = Schema.getGlobalDescribe().get(splitStateString[0]).getDescribe().fields.getMap().get(splitStateString[1]);
System.debug('State Field: ' + stateField);
String countryString = 'Contact.MailingCountry';
List<String> splitCountryString = countryString.split('\\.');
Schema.SobjectField countryField = Schema.getGlobalDescribe().get(splitCountryString[0]).getDescribe().fields.getMap().get(splitCountryString[1]);
System.debug('Country Field: ' + countryField);
DependentPicklists dp = new DependentPicklists();
Map<String, List<String>> result = dp.controllingToDependentValues(countryField, stateField);
System.debug(result.size());
System.debug(result.keySet().size());
System.debug(result);
The result is as follows:
12:00:02.44 (156941497)|USER_DEBUG|[7]|DEBUG|State Field: MailingState
12:00:02.44 (166692772)|USER_DEBUG|[15]|DEBUG|Country Field: MailingCountry
12:00:02.44 (170849255)|USER_DEBUG|[21]|DEBUG|0
12:00:02.44 (170924837)|USER_DEBUG|[22]|DEBUG|0
12:00:02.44 (170952466)|USER_DEBUG|[23]|DEBUG|{}
What am I missing that is keeping me from getting results?