/***********Custom setting **********/
Map<string, CountryCO__c> codes = CountryCO__c.getAll(); 
        string pb;
        list<string> pb1=new list<string>();

           for (string key: codes.keyset())
                CountryCO__c code = codes.get(key);
               pb=code.Country_code__c ;

List<CountryListWrapper> CountryList= new List<CountryListWrapper>(); 

 List<Country__c> countrynew = new List<Country__c> ([Select Countrycode,price,state from Country__c ] ) ; //Custom object

      for(Country__c c: countrynew ) {  

              CountryListWrapper cl = new CountryListWrapper();

                cl .Countrycode = c.Country_code__c ;
                cl .Prodprice uctCode = c.price__c ;
                cl .state = c.state__c ;
                CountryList.add(cl );

/*******Wrapper class*********/
 public class CountryListWrapper{
        @AuraEnabled public Integer Countrycode {get;set;}
 @AuraEnabled public Integer price {get;set;}
 @AuraEnabled public Integer state {get;set;}

I have created a custom setting with two fields(Country,Country Code).How to create a map with these two fields,so that I can take key's value and assign it to a wrapper class variable?The variable in wrapper class is assigned to a list containing custom object fields. Of-which one field in custom object is Country Code,which should be assigned with custom settings Country code field value.

  • Have you taken a look at the documentation? You will get examples of how to retrieve values from custom setting and assign it to any variable/field you want.
    – Jayant Das
    Commented Aug 24, 2018 at 12:34
  • Based on your edit and your comment, I'm really not sure what you're asking. Your code as presented here will not compile for a variety of reasons. Would you take a minute to read How to Ask and try to make this question clear and specific?
    – David Reed
    Commented Aug 24, 2018 at 13:10

1 Answer 1


You can get most of the way there with built-in Custom Settings methods.

If you utilize the Name field on your custom setting for the country code and, say, Country_Name__c for the name, you can call

Map<String, My_Custom_Setting__c> myMap = My_Custom_Setting__c.getAll();

Then your Map will have the country codes as its keys, and the Custom Settings objects as its values, so you can just do


to get a name.

For bonus points, wrap this in a utility class to make it easy to just call


But this saves you the need to iterate and build your own Map.

  • Thanks Much.I have added sample of my code.Can you please tell me where to add the custom setting value so that it can change country code in custom object. Commented Aug 24, 2018 at 13:08
  • For instance in my custom object the value in country code is displayed as Country1, Country2....In custom settings I have assigned value like Country1 is 001,Country2 is 002.,etc., Now i wanted this code to be displayed.Please help me. Commented Aug 24, 2018 at 13:10

You must log in to answer this question.

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