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()+',';
}
sQuerry = sQuerry.substring(0,sQuerry.length()-1);
sQuerry = sQuerry+' From Lead';
ldList = Database.query(sQuerry );
system.debug('Printing--sQuerry-'+sQuerry)
How to assign value entered from page to lead list
for(Schema.FieldSetMember f : SObjectType.Lead.FieldSets.Update_BDR_Activity_Fields.getFields()) {
System.debug('Printing-leadTemp.get(f.getFieldPath())--'+leadTemp.get(f.getFieldPath()));
if(leadTemp.get(f.getFieldPath()) != null){
System.debug('inside iffff');
Lead1.put(f.getFieldPath(),leadTemp.get(f.getFieldPath()));
}
}
updtleads.add(Lead1);
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()+',';
}
sQuerry = sQuerry.substring(0,sQuerry.length()-1);
sQuerry = sQuerry+' From Lead';
ldList = Database.query(sQuerry );
system.debug('Printing--sQuerry-'+sQuerry)
How to assign value entered from page to lead list
for(Schema.FieldSetMember f : SObjectType.Lead.FieldSets.Update_BDR_Activity_Fields.getFields()) {
System.debug('Printing-leadTemp.get(f.getFieldPath())--'+leadTemp.get(f.getFieldPath()));
if(leadTemp.get(f.getFieldPath()) != null){
System.debug('inside iffff');
Lead1.put(f.getFieldPath(),leadTemp.get(f.getFieldPath()));
}
}
updtleads.add(Lead1);
No comments:
Post a Comment