TaxesH__c => Public Hierarchy
- If you want to track new custom fields use CUTOM FIELDS SECTION.
- If you want to track just records use VALUES SECTION
- Hierarchy custom fields
- Hierarchy records
<apex:page showHeader="true" sidebar="true" controller="CustomSettingsController">
<apex:form>
<!-- CUTOM FIELDS SECTION -->
<apex:pageBlock>
<apex:pageBlockSection title="CUTOM FIELDS SECTION" collapsible="false">
<apex:selectList value="{!selectedTaxCustomField}" size="1">
<apex:selectOptions value="{!taxFields}"/>
</apex:selectList>
</apex:pageBlockSection>
</apex:selectList>pageBlock>
<!-- VALUES SECTION -->
<apex:pageBlock>
<apex:pageBlockSection title="VALUES SECTION" collapsible="false">
<apex:selectList value="{!selectedTaxValues}" size="1">
<apex:selectOptions value="{!taxValues}"/>
</apex:pageBlockSection>selectList>
</apex:pageBlock>
pageBlockSection>
</apex:pageBlock>
<!-- VALUESHIERARCHY FIELDS SECTION -->
<apex:pageBlock>
<apex:pageBlock>pageBlockSection title="HIERARCHY FIELDS SECTION" collapsible="false">
<apex:pageBlockSection title="VALUESselectList SECTION"value="{!selectedTaxHField}" collapsible="false">size="1">
<apex:selectListselectOptions value="{!selectedTaxValuestaxHFields}"/>
size="1"> </apex:selectList>
</apex:pageBlockSection>
</apex:pageBlock>
<!-- HIERARCHY FIELDS SECTION -->
<apex:pageBlock>
<apex:pageBlockSection title="HIERARCHY VALUES SECTION" collapsible="false">
<apex:selectOptionsselectList value="{!taxValuesselectedTaxHValue}"/> size="1">
</apex<apex:selectList>selectOptions value="{!taxHValues}"/>
</apex:pageBlockSection>selectList>
</apex:pageBlock>pageBlockSection>
</apex:form>pageBlock>
</apex:page>form>
</apex:page>
Apex Controller:
public with sharing class CustomSettingsController {
public String selectedTaxCustomField { get; set; }
public List<SelectOption> taxFields { get; set; }
public String selectedTaxValues { get; set; }
public StringList<SelectOption> selectedTaxValuestaxValues { get; set; }
public String selectedTaxHField { get; set; }
public List<SelectOption> taxValuestaxHFields { get; set; }
public String selectedTaxHValue { get; set; }
public CustomSettingsController()List<SelectOption> taxHValues {
get; set; }
public CustomSettingsController() {
//CUTOM FIELDS SECTION
taxFields = new List<SelectOption>();
Map<String,Schema.SObjectField> fieldsMap = Taxes__c.sObjectType.getDescribe().fields.getMap();
for (String field : fieldsMap.keySet()) {
Schema.SObjectField F = fieldsMap.get(field);
Schema.DescribeFieldResult R = F.getDescribe();
if (R.isCustom()) {
String fName = R.getName();
String fLabel = R.getLabel();
taxFields.add(new SelectOption(fName, fLabel));
}
}
//VALUES SECTION
}
taxValues = new List<SelectOption>();
//VALUES SECTION
Map<String, Taxes__c> allTaxesSettings = Taxes__c.getAll();
//testfor data
(String taxKey : allTaxesSettings.keySet()) {
//insert new Taxes__c(Name = 'Tax1',Taxes__c Value__caTax = '1'allTaxesSettings.get(taxKey);
//insert taxValues.add(new Taxes__cSelectOption(aTax.Name = 'Tax2', aTax.Value__c = '2'));
}
//insertHIERARCHY FIELDS SECTION
taxHFields = new Taxes__cList<SelectOption>(Name);
= 'Tax3' Map<String,Schema.SObjectField> Value__cfieldsHMap = '3'TaxesH__c.sObjectType.getDescribe().fields.getMap();
//holds custom field names, used taxValuesto dynamically get values
Set<String> customHierarchyFieldNames = new List<SelectOption>Set<String>();
for (String field : Map<String,fieldsHMap.keySet()) Taxes__c>{
allTaxesSettings Schema.SObjectField F = Taxes__cfieldsMap.getAllget(field);
forSchema.DescribeFieldResult R = F.getDescribe(String);
taxKey : allTaxesSettings if (R.keySetisCustom()) {
Taxes__cString aTaxfName = allTaxesSettingsR.getgetName(taxKey);
taxValuesString fLabel = R.getLabel();
taxHFields.add(new SelectOption(aTax.NamefName, aTax.Value__cfLabel));
customHierarchyFieldNames.add(fName);
}
}
//HIERARCHY VALUES
taxHValues = new List<SelectOption>();
TaxesH__c allTaxesHSettings = TaxesH__c.getInstance();
for (String fName : customHierarchyFieldNames) {
taxHValues.add(new SelectOption(fName, String.valueOf(allTaxesHSettings.get(fName))));
}
}
}