dynamic visualforce bindings example

You will find many articles about complex Dynamic visual force examples, ready made packages for dynamic visualforce pages. Well, i am not going to post here any complex dynamic visualforce page. Rather, i am going to post a simple dynamic visualforce page that will be useful for a developer who has recently started coding.

Here's a page that demonstrates how you can build your first dynamic visualforce page.
What will be dynamic in the page?
* Object name

You can select whichever object name you want. Just change it in the custom label. Your visualforce page will display 10 records of that object in a table.It will display only two fields ID and Name in the table. Have chosen only two fields because you will find these fields in all the objects (Custom as well as standard). Page can be improvised to select fields dynamically using fieldset. Just to keep it simple i have taken only two fields.

Just create a custom label with name "Object_Name_Label"

this custom label will store the api name of your object (standard or custom).

Following is the visualforce page


You have to just change the custom label's value and you will get that particular object's 10 records displayed in the table.
Let us understand the visualforce tabel and the repeat attribute used here,
<apex:pageBlockTable value="{!sObjectList}" var="sObjRec">
      <apex:repeat value="{!fieldList}" var="sObjField">
        <apex:column value="{!sObjRec[sObjField]}"/>

"sObjectList" is the list which stores records of your object, "sObjRec" is the variable used to represent each of the record in list.
"fieldList" is the list of string that stores field api names (ID and Name in this case), "sObjField" represent each field name.

Repeat is just like a for loop which iterates on the list of strings(field api names) stored in fieldList, giving number of columns for each field name. Also pagblocktable iterates over "sObjectList".

Let me know if you need any assistance on this.


  1. Hi Yoganand,

    I am trying to use dynamic visualforce page to display custom labels (long labels) for my fields.
    Basically my idea is to store these labels as records in a child object and then use these records as the labels for the fields in the parent object.
    Do you think this idea is feasible?
    I would really appreciate if you could share some sample code or give me any feedback.

    1. You can use lables for storing the field labels. You can access teh abels directly in visauflorce page as --> value="{!$Label.Sample}"

  2. i done label and codes, but how can i run this?

  3. hiiii..... how can we get the records with selected field values of an sobject selected dynamically