Sometimes we don't know which fields should be displayed in the page and which field should be added in the query. To solve this issue and make it salable SFDC has given cool features called Field set. This post will share some code snippet about using field set in the page and in controller. In the page <apex:repeat value="{!$ObjectType.Lead.FieldSets.Update_Fields_FieldSET}" var="f"> <apex:inputField value="{!leadTemp [f]}"/><br/> </apex:repeat> Public Lead leadTemp {get;set;} In the apex class String sQuerry = 'Select id,GEO__c,Is_Locked__c,'; for(Schema.FieldSetMember f : SObjectType.Lead.FieldSets.Update_BDR_Activity_Fields.getFields()) { sQuerry = sQuerry+f.getFieldPath()+','; } ...