I am a newbie,so i dont know how to work around with custom settings.In the requirement there is a custom setting object called OppCountryRegionMapping__c.In this object there are 2 fields,region__c and country__c.Below is the screenshots of custom settings.
When i click on manage there are records,which have records.
When i select particular record,it will have the values for Name,region and country.
Like
Name-->AustraliaAsia
Region-->Asia
Country-->Australia
I have to develop a page where region and country should be picklist.The region should show all distinct regions and when i select particular region from the picklist the corresponding countries should be displayed in the country picklist.
I have tried with the following visualforce and apex code.
Visualforce
<apex:page Controller="testing_custom">
<apex:form >
<apex:selectList label="Region" value="{!region}" size="1" multiselect="false">
<apex:selectOptions value="{!regionsSelectList}"/>
</apex:selectList>
<apex:selectList label="Country" value="{!country}" size="1" multiselect="false">
<apex:selectOptions value="{!CountriesSelectList}}"/>
</apex:selectList>
</apex:form>
</apex:page>
Apex
public class testing_custom
{
public String region{get;set; }
public String country{get;set;}
//For getting region list from custom settings object
public List<SelectOption> getregionsSelectList(){
List<SelectOption> options = new List<SelectOption>();
set<String> setUniqueRegion = new set<String>();
for(OppCountryRegionMapping__c setting : OppCountryRegionMapping__c.getAll().values()){
if(!setUniqueRegion.contains(setting.Region__c)){
options.add(new SelectOption(setting.name, setting.Region__c));
setUniqueRegion.add(setting.Region__c);
}
}
return options;
}
//For getting country list based on selected region from custom settings object
public List<SelectOption> getCountriesSelectList() {
List<SelectOption> options = new List<SelectOption>();
for(OppCountryRegionMapping__c setting : OppCountryRegionMapping__c.getAll().values()) {
if (setting.Region__c== this.region) {
options.add(new SelectOption(setting.name,setting.Country__c));
}
}
system.debug('*****selected value inside'+options);
return options;
}
This is getting duplicate values of region also,
i tried placing the values in the set.But it will not work.How have to proceed with this.Help me.
Thanks