Showing posts with label visualforce. Show all posts
Showing posts with label visualforce. Show all posts

Tuesday, May 31, 2011

Dynamic Binding Salesforce

Visualforce Dynamic Binding lets you write generic Visualforce pages to display information about records without necessarily knowing which fields to show. By determining the fields to show at runtime rather than compile time, Visualforce Dynamic Bindings allows for the presentation of data specific to each subscriber with very little coding. Developers working with managed packages will find this feature especially useful.

In the below example I have created a class and fetching all the fields of account object in that class.

public class DynamicBinding
{
    public Account account{get;set;}
    
    // constructor
    public DynamicBinding(){
        account = new Account();
    }
    
    // get sobject fields of account object
    public static List<String> getSobjectFields() 
       {
            List<String> fields = new List<String>();
            
            Map<String,Schema.SObjectType> gd = Schema.getGlobalDescribe();
            Schema.SObjectType sobjType = gd.get('account');
            Schema.DescribeSObjectResult r = sobjType.getDescribe();
            Map<String,Schema.SObjectField> M = r.fields.getMap();
            
            for(String fieldName : M.keyset())
                {
                    Schema.SObjectField field = M.get(fieldName);                                                    
                    Schema.DescribeFieldResult fieldDesc = field.getDescribe();
                    fields.add(fieldName.toLowerCase());
                }
            return fields;
       }   
}

I have created a vf page and set it controller to "DynamicBinding" class.I am using the account object and "SobjectFields" property to create the page dynamically.

<apex:page controller="DynamicBinding">
  <apex:form >
      <apex:pageBlock>
          <apex:pageBlockSection>
              <apex:repeat value="{!SobjectFields}" var="fieldName">
                   <apex:inputField value="{!account[fieldName]}"/>
              </apex:repeat>
          </apex:pageBlockSection>
      </apex:pageBlock>
  </apex:form>
</apex:page>
Thanks,

How to use FieldSet on VisualForce page

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. Field sets can be referenced on Visualforce pages dynamically. 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.

I have created a fieldset on Account Object .



How to use Fieldset on vf page-