1

This question already has an answer here:

I have enabled state and picklist value in client's unlimited org. I need to access only dependent state based on selected Country code. There are some integration and other apex changes where I need only dependent state value in a Map( like : 'MH'=> 'Maharastra')... I am using below code but It will give all the state values. I need only states based on country values. e.g. : For Indian it should have only 35 state which belong to India only.

Schema.DescribeFieldResult F = Contact.MailingStateCode.getDescribe();
List<Schema.PicklistEntry> P = F.getPicklistValues();

System.debug('-----P--->>'+P[0]);
Map<String, String> tempMap = new Map<String, String>();
for(Schema.PicklistEntry sp : P){
    tempMap.put(sp.getValue(), sp.getLabel());
}

System.debug('----tempMap-----'+tempMap.get('MH'));  // Here it is returning 'Meath' as MH will be state code for some other states as well 
System.debug('----tempMapVALUE-----'+tempMap.get('UP'));

Any help will be appreciated. Thanks in Adance !!

marked as duplicate by Vamsi Krishna, crmprogdev, Sergej Utko, AtulRajguru9, Chris Duncombe Jun 1 '15 at 14:23

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

try this

Schema.DescribeFieldResult fieldResult =  Account.Industry.getDescribe();   
List<Schema.PicklistEntry> plv = fieldResult.gettextValues();

for( Schema.PicklistEntry f : plv)
   {
       System.debug('Field Label ' + f.getLabel());
       System.debug('Field Value ' + f.getValue());
   }
  • Thanks Vamsi, Above code in questionn is also working fine. But my questions is that. is there any way we can filter the state picklist values in apex by passing Country Name.. lets sat we are passing 'IN' they it should return only states which belongs to India in apex code(not on VF page). – Nitish Mishra Jun 1 '15 at 15:25

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