So I got my Visualforce Page to display a table with columns (e.g. Version, Date, Type, etc.) as well as values from a dataset for each corresponding column of the next rows.

I'm trying to integrate Custom Settings in the form of selected fields, to be able to determine which columns show up on the Visualforce Page. I've created a Select Fields custom setting in the form of checkboxes for each column name.

Here's my markup without the custom settings integration:

    <apex:includescript value="//code.jquery.com/jquery-1.11.1.min.js" / >
    <apex:includescript value="//cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js" />
    <apex:stylesheet value="//cdn.datatables.net/1.10.4/css/jquery.dataTables.css" />
        j$ = jQuery.noConflict();
        j$(document).ready( function () {
            var Timeline = j$('[id$="Timeline"]').DataTable({

    <table id="Timeline" class="display">

                <th>Subscription Version</th>
                <th>Start Date</th>
                <th>End Date</th>
                <th>Amendment Date</th>
                <th>Amendment Type</th>
                <th>Amendment Description</th>
                <th>Charge Name</th>
                <th>Charge Price</th>

            <apex:repeat value="{!subscriptionInfo}" var="cs"> 


Use a Field Set instead. It was designed with this scenario in mind.

Working with Field Sets

You can use dynamic bindings to display field sets on your Visualforce pages. A field set is a grouping of fields. For example, you could have a field set that contains fields describing a user's first name, middle name, last name, and business title. If the page is added to a managed package, administrators can add, remove, or reorder fields in a field set to modify the fields presented on the Visualforce page without modifying any code. Field sets are available for Visualforce pages on API version 21.0 or above. You can have up to 50 field sets referenced on a single page.

Working with Field Sets Using Visualforce

Field sets can be directly referenced in Visualforce by combining the $ObjectType global variable with the keyword FieldSets. For example, if your Contact object has a field set called properNames that displays three fields, your Visualforce page can reference the field data through the following iteration:

<apex:page standardController="Contact">
    <apex:repeat value="{!$ObjectType.Contact.FieldSets.properNames}" var="f"> 
        <apex:outputText value="{!Contact[f]}" /><br/>

In your case, you would need to use it once for the headers, and again for the data.

    <apex:repeat value="{!$ObjectType.MyObject__c.FieldSets.MyFieldSet}" var="field">
    <apex:repeat value="{!subscriptionInfo}" var="record">
            <apex:repeat value="{!$ObjectType.MyObject__c.FieldSets.MyFieldSet}" var="field">

You can access custom setting in Visualforce page through global variable $Setup.

Include your columns in apex:outputPanel and use rendered attribute to display the columns.

<apex:outputPanel id="helpWorkstationHeight" rendered="{!$Setup.App_Prefs__c.Show_Help_Content__c}"> 
<th>Subscription Version</th> 

Link : https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_variables_global_setup.htm

  • 2
    Worth noting this approach only works for a Hierarchy Custom Setting. – Adrian Larson Jul 27 '16 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.