function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Kevin Jackson 11Kevin Jackson 11 

How to get countries in a list in APEX

Hi Have scanned the resources and cannot find a solution that works:

I know it has to be done along these lines here:

public static void getCountries()
        Schema.DescribeFieldResult fieldResult = Contact.MailingCountryCode.getDescribe();
        List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
        for(Schema.PicklistEntry s:ple){
            System.debug('value: '+s.getLabel());

BUT I get this error :  "Method does not exist or incorrect signature: void getDescribe() from the type String"

With VF Page including:

<apex:selectList value="{!Country}" size="1" required="true">
                    <apex:selectOptions value="{!Countriesj}"/>

I have tried other code, like the one from @gregorz Skaruz

It looks great, but is is coming up with an empty Select options List.

Any Help is appreciated.
Amit Chaudhary 8Amit Chaudhary 8
Did you try code like below

  Schema.sObjectType objType = Contact.getSObjectType();
  Schema.DescribeSObjectResult objDescribe = objType.getDescribe();
  map<String, Schema.SObjectField> fieldMap = objDescribe.fields.getMap();
  list<Schema.PicklistEntry> values = fieldMap.get('MailingCountryCode').getDescribe().getPickListValues();

  List<SelectOption> options = new List<SelectOption>();
  for (Schema.PicklistEntry v : values){
    options.add(new SelectOption(v.getLabel(), v.getLabel()));