I have enabled State and Country Picklists in my org. I am getting values in piclist. But the are not dependent. Like if i select country "India" i should get states only related to india. But it is not happening so.
<apex:page controller="dependentCountryandState" >
<apex:form >
<apex:selectList id="countries" value="{!tmpContact}" size="1" required="true">
<apex:selectOptions value="{!countries}"/>
</apex:selectList>
<apex:selectList id="states" value="{!tmpState}" size="1" required="true">
<apex:selectOptions value="{!states}"/>
</apex:selectList>
</apex:form>
public with sharing class dependentCountryandState {
public String tmpState { get; set; }
public String tmpContact { get; set; }
public List<SelectOption> getCountries()
{
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.getValue(), v.getLabel()));
}
return options;
}
public List<SelectOption> getStates()
{
Schema.sObjectType objType = Contact.getSObjectType();
Schema.DescribeSObjectResult objDescribe = objType.getDescribe();
map<String, Schema.SObjectField> fieldMap = objDescribe.fields.getMap();
list<Schema.PicklistEntry> values = fieldMap.get('MailingStateCode').getDescribe().getPickListValues();
List<SelectOption> options = new List<SelectOption>();
for (Schema.PicklistEntry v : values){
options.add(new SelectOption(v.getLabel(), v.getLabel()));
}
return options;
}
}
How to get dependent state for the dependent country code?
<apex:inputField Value="{!Contact.ContryCode}"> and <apex:inputField Value="{!Contact.StateCode}">
for dependent picklist