Skip to main content
added hierarchy settings example
Source Link

TaxesH__c => Public Hierarchy

  1. If you want to track new custom fields use CUTOM FIELDS SECTION.
  2. If you want to track just records use VALUES SECTION
  3. Hierarchy custom fields
  4. 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))));
    }
}

}

  1. If you want to track new custom fields use CUTOM FIELDS SECTION.
  2. If you want to track just records use VALUES SECTION
    <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:pageBlock>

        <!-- VALUES SECTION -->
        <apex:pageBlock>
            <apex:pageBlockSection title="VALUES SECTION" collapsible="false">
                <apex:selectList value="{!selectedTaxValues}" size="1">
                    <apex:selectOptions value="{!taxValues}"/>
                </apex:selectList>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex: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 List<SelectOption> taxValues { 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
        //test data
        //insert new Taxes__c(Name = 'Tax1', Value__c = '1');
        //insert new Taxes__c(Name = 'Tax2', Value__c = '2');
        //insert new Taxes__c(Name = 'Tax3', Value__c = '3');
        taxValues = new List<SelectOption>();
        Map<String, Taxes__c> allTaxesSettings = Taxes__c.getAll();
        for (String taxKey : allTaxesSettings.keySet()) {
            Taxes__c aTax = allTaxesSettings.get(taxKey);
            taxValues.add(new SelectOption(aTax.Name, aTax.Value__c));
        }
    }
}

TaxesH__c => Public Hierarchy

  1. If you want to track new custom fields use CUTOM FIELDS SECTION.
  2. If you want to track just records use VALUES SECTION
  3. Hierarchy custom fields
  4. 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:pageBlock>

    <!-- VALUES SECTION -->
    <apex:pageBlock>
        <apex:pageBlockSection title="VALUES SECTION" collapsible="false">
            <apex:selectList value="{!selectedTaxValues}" size="1">
                <apex:selectOptions value="{!taxValues}"/>
            </apex:selectList>
        </apex:pageBlockSection>
    </apex:pageBlock>

    <!-- HIERARCHY FIELDS SECTION -->
    <apex:pageBlock>
        <apex:pageBlockSection title="HIERARCHY FIELDS SECTION" collapsible="false">
            <apex:selectList value="{!selectedTaxHField}" size="1">
                <apex:selectOptions value="{!taxHFields}"/>
            </apex:selectList>
        </apex:pageBlockSection>
    </apex:pageBlock>

    <!-- HIERARCHY FIELDS SECTION -->
    <apex:pageBlock>
        <apex:pageBlockSection title="HIERARCHY VALUES SECTION" collapsible="false">
            <apex:selectList value="{!selectedTaxHValue}" size="1">
                <apex:selectOptions value="{!taxHValues}"/>
            </apex:selectList>
        </apex:pageBlockSection>
    </apex:pageBlock>

</apex: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 List<SelectOption> taxValues { get; set; } 

public String selectedTaxHField { get; set; }
public List<SelectOption> taxHFields { get; set; }

public String selectedTaxHValue { get; set; }
public 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>();
    Map<String, Taxes__c> allTaxesSettings = Taxes__c.getAll();
    for (String taxKey : allTaxesSettings.keySet()) {
        Taxes__c aTax = allTaxesSettings.get(taxKey);
        taxValues.add(new SelectOption(aTax.Name, aTax.Value__c));
    }

    //HIERARCHY FIELDS SECTION
    taxHFields = new List<SelectOption>();
    Map<String,Schema.SObjectField> fieldsHMap = TaxesH__c.sObjectType.getDescribe().fields.getMap(); 

    //holds custom field names, used to dynamically get values
    Set<String> customHierarchyFieldNames = new Set<String>(); 

    for (String field : fieldsHMap.keySet()) {
        Schema.SObjectField F = fieldsMap.get(field);
        Schema.DescribeFieldResult R = F.getDescribe();
        if (R.isCustom()) {
            String fName = R.getName();
            String fLabel = R.getLabel();
            taxHFields.add(new SelectOption(fName, fLabel));
            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))));
    }
}

}

Source Link

here it is small example. Taxes__c => Public List Custom Settings. Value__c => 1st custom field. Value2__c => 2nd custom field.

  1. If you want to track new custom fields use CUTOM FIELDS SECTION.
  2. If you want to track just records use VALUES SECTION

Apex Page:

    <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:pageBlock>

        <!-- VALUES SECTION -->
        <apex:pageBlock>
            <apex:pageBlockSection title="VALUES SECTION" collapsible="false">
                <apex:selectList value="{!selectedTaxValues}" size="1">
                    <apex:selectOptions value="{!taxValues}"/>
                </apex:selectList>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex: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 List<SelectOption> taxValues { 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
        //test data
        //insert new Taxes__c(Name = 'Tax1', Value__c = '1');
        //insert new Taxes__c(Name = 'Tax2', Value__c = '2');
        //insert new Taxes__c(Name = 'Tax3', Value__c = '3');
        taxValues = new List<SelectOption>();
        Map<String, Taxes__c> allTaxesSettings = Taxes__c.getAll();
        for (String taxKey : allTaxesSettings.keySet()) {
            Taxes__c aTax = allTaxesSettings.get(taxKey);
            taxValues.add(new SelectOption(aTax.Name, aTax.Value__c));
        }
    }
}