Step 1: Create Field set in Account Object.
Setup->Customize->Account->Field Sets
Drag and Drop the fields required for the Field Set
Step 2: Create Visual Force Page
<apex:repeat value="{!lstAccount}" var="acc"> <table width="100%"> <apex:repeat value="{!$ObjectType.Account.FieldSets.Account_FieldSet}" var="fieldSet"> <tr> <td> {!fieldSet.Label} </td> <td> <apex:inputField value="{!acc[fieldSet]}"/> </td> </tr> </apex:repeat> </table> </apex:repeat>
Step 3: Write the Controller for the VisualForce Page
public with sharing class DynamicTabController
{
public List<Account> lstAccount{get;set;}
public DynamicTabController()
{
lstAccount=new List<Account>();
String query = 'SELECT ';
for(Schema.FieldSetMember f : this.getFields())
{
query += f.getFieldPath() + ', ';
}
query += ' Id FROM Account limit 5 ';
System.debug('query ------>'+query );
lstAccount = Database.query(query);
}
public List<Schema.FieldSetMember> getFields()
{
return SObjectType.Account.FieldSets.Account_FieldSet.getFields();
}
}
Thanks,
Amit Chaudhary
osmaniye
ReplyDeleterize
sakarya
samsun
sivas
WL5C