0

How do I get a dependent list of States by Country from Salesforce via API?

Our Use Case is: We need dependent Picklists on an integrated 3rd party web platform we intend to pass the returned Countries and STate into a JS array so that we can make the Country field control the State field . We have States&Countries enabled in settings.

We prefer REST.

1 Answer 1

1

You can't get the values in a convenient REST resource by itself, but if you describe the object, you'll get the dependencies:

/services/data/v43.0/sobjects/Account/describe

This gives back a JSON that includes all fields, record type information, etc. If you look at the fields object, you'll find BillingStateCode, which contains picklistValues, which is a list that includes the value, label, and the validFor bitmap.

You'll want to read this answer for how to decode validFor. Basically, you read the bits from left to right; if it's a 1 bit, then the picklist value in the controlling field is valid, otherwise not.

1
  • Great Answers, this and the other question, thanks again. My integrator doesn't want to consume the describe and do the translation, so I will build a Web Service with it in a more usable array format, and they can consume that. Jun 28, 2018 at 12:42

You must log in to answer this question.

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