My example based on the following settings:
- Custom object: MyObject__c
- A normal picklist: Picklist__c
- Custom setting object: MySettingsList__c
- Custom setting fields: Setting1 and Setting2
First i will read all values of the custom picklist and add it to the select option list. Then read the custom settings and add it to the list too.
Controller:
public String selectedValue { get; set; }
public List<SelectOption> getMyOptions(){
List<SelectOption> options = new List<SelectOption>();
// Reading picklist values and labels
Schema.DescribeFieldResult fieldResult = MyObject__c.Picklist__c.getDescribe();
List<Schema.PicklistEntry> picklistEntries = fieldResult.getPicklistValues();
// Adding apicklist values to the select list
for(Schema.PicklistEntry entry : picklistEntries){
options.add(new SelectOption(entry.getValue(), entry.getLabel()));
}
// Now adding custom settings to the select list
for(MySettingsList__c setting : MySettingsList__c.getAll().values()){
options.add(new SelectOption(setting.name, setting.Setting1__c));
options.add(new SelectOption(setting.name, setting.Setting2__c));
}
return options;
}
Visualforce page:
<apex:selectList value="{!selectedValue}" size="1" multiselect="false">
<apex:selectOptions value="{!MyOptions}"/>
</apex:selectList>
Then it should look like this: