2

I would like to get values for Address.Setting Metadata Component in Salesforce.There are stored all country and state ISO codes.

<?xml version="1.0" encoding="UTF-8"?>
<AddressSettings xmlns="http://soap.sforce.com/2006/04/metadata">
    <countriesAndStates>
        <countries>
            <active>true</active>
            <integrationValue>Andorra</integrationValue>
            **<isoCode>AD</isoCode>
            <label>Andorra</label>**
            <orgDefault>false</orgDefault>
            <standard>true</standard>
            <visible>true</visible>
        </countries>
        <countries>
            <active>true</active>
            <integrationValue>Yhdistyneet Arabiemiirikunnat</integrationValue>
            <isoCode>AE</isoCode>
            <label>Yhdistyneet Arabiemiirikunnat</label>
            <orgDefault>false</orgDefault>
            <standard>true</standard>
            <visible>true</visible>
        </countries>

Is there a way to "query" this data, i mean, for example, passing Andorra to get related ISO code "AD".

<countries>
                <active>true</active>
                <integrationValue>Andorra</integrationValue>
                **<isoCode>AD</isoCode>
                <label>Andorra</label>**
                <orgDefault>false</orgDefault>
                <standard>true</standard>
                <visible>true</visible>
            </countries>

I don´t want to turn on the Salesforce Feature named "Country and State picklist". I want to access with apex code the metadata file that is used to implement this feature(xml above is coming from there). This metadata file is named:"address.settings"

Do i need to use metadata Api?

How i can accomplish that?

Thanks in advantage for any advice.

2
  • 1
    Please update your question to make it clear that you want to access this data from Apex code (which I assume but may be wrong about) rather than from development tools or external code. You need this data for functionality beyond the standard features (na15.salesforce.com/help/pdfs/en/…) right?
    – Keith C
    Commented Mar 2, 2014 at 18:14
  • I don't think what you're asking for is possible. Address.Settings is only used for the state/country picklist feature. If you're not interested in the feature, you could write your own static Apex method with a map of country name to country code. Commented Mar 3, 2014 at 21:20

1 Answer 1

1
Map<String,String> maplabelVal=new Map<String,String>();
// Get the object type of the SObject.
Schema.sObjectType objType = Contact.getSObjectType(); 
// Describe the SObject using its object type.
Schema.DescribeSObjectResult objDescribe = objType.getDescribe();       
// Get a map of fields for the SObject
map<String, Schema.SObjectField> fieldMap = objDescribe.fields.getMap(); 
// Get the list of picklist values for this field.
list<Schema.PicklistEntry> values = fieldMap.get('MailingCountryCode').getDescribe().getPickListValues();
// Add these values to the selectoption list.
for (Schema.PicklistEntry a : values){ 
    maplabelVal.put(a.getLabel(), a.getValue()); 
}
system.debug('*****'+maplabelVal);
system.debug('ISO CODE'+maplabelVal.get('Andorra'));

You can directly store these with describe calls in MAP as above code


0:06:08:081 USER_DEBUG [14]|DEBUG|*{Afghanistan=AF, Afrique du Sud=ZA, Albanie=AL, Algérie=DZ, Allemagne=DE, Andorra=AD, Angola=AO, Anguilla=AI, Antarctique=AQ, Antigua et Barbuda=AG, ...}

2
  • Thanks Mohith, but it´s not what i´m looking for. I don´t have that picklist field because in my org it´s not enabled feature "State and Country Picklist". I want access in apex a metadata Salesforce file without turn on this feature.The metadata file it´s named" Address.Settings" Do you know how can i do that? Thanks again
    – Enry
    Commented Mar 3, 2014 at 19:45
  • @Enry You will need to store in custom setting from wiki and include all states as well if you need for each country. Commented Mar 4, 2014 at 6:30

You must log in to answer this question.

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