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);


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?


1 Answer 1


This probably does not help @Swisher Sweet, who I am sure has gotten this working in the past year and a half; but for future seekers (like myself)....


You have to use Contact.MailingCountryCode and Contact.MailingStateCode.

(Or other objects and fields, like:

Account.BillingCountryCode and Account.BillingStateCode.

It is the appended Code that is important.)


  1. I haven't yet found an explicit statement in Salesforce documentation about these fields used in this context. (I also haven't overturned every stone.) The best I have found referencing using these fields at all is here:

    SALESFORCE HELP > DOCS > SET UP AND MAINTAIN YOUR SALESFORCE ORGANIZATION > Provide Maps and Location Services > Let Users Select State and Country from Picklists

    Under State and Country Picklist Limitations:

    You can access your records’ state and country code values by using the StateCode and CountryCode fields in Workbench or the Data Loader.

  2. It is stated/included/mentioned-in-passing in questions, answers and comments all over this forum. Here are a few:

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .