DYNAMIC VISUALFORCE BINDINGS
Today in this post, I will explain about “Dynamic VisualForce Bindings”. This was introduced in Spring’11 release and it allows developer to choose the list of fields to be displayed at run time, rather than at compile time. As a result, developer can write generic VisualForce pages which will display information about records without necessarily knowing the list of fields.Dynamic VisualForce Binding is supported for both standard and custom objects. The general form isreference[expression]where -reference – It can be either an sObject, or an Apex Class, or a global variable.expression – It evaluates to a String that is the name of a field, or a related object. In case of related object, it can be used recursively to select another related object or field.Important point – Dynamic VisualForce Page should always use a standard controller for the object and then implement any further customization through controller extensions.The below example will show how dynamic visualforce binding can be implemented to display list of fields from Account object at run time.Controller – ShowDynamicAccountFieldController 1 2 3 4 5 6 7 8 910111213141516171819202122232425262728293031323334353637383940414243444546474849public with sharing class ShowDynamicAccountFieldController { public ShowDynamicAccountFieldController(ApexPages.StandardController controller){ controller.addFields(dynamicFields); Account acc = (Account) controller.getRecord(); } public List<String> dynamicFields{ get{ if(dynamicFields == null){ dynamicFields = new List<String>(); dynamicFields.add(‘Name’); dynamicFields.add(‘AccountSource’); dynamicFields.add(‘NumberOfEmployees’); dynamicFields.add(‘Rating’); } return dynamicFields; } private set; } public void showFirstSet(){ checkAndInitiate(); dynamicFields.clear(); dynamicFields.add(‘Name’); dynamicFields.add(‘AccountSource’); } public void showSecondSet(){ checkAndInitiate();...
Read More