1

I want to write an Apex method that takes a country name as input and returns the equivalent two letter country code (ISO A2). Is there a way to write it without explicitly hard coding all countries and code in the method?

7

Are you using State and Country Picklists? If so, you can just describe any standard country picklist (e.g. Contact.CountryCode). Otherwise, you can always load the list of countries into a Custom Metadata Type, or using Custom Settings, which allows you to customize the values that are contained in the list.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.