Get fields in SOQL from FIeldSet
global class BatchclassName implements Database.Batchable<sObject>, Database.Stateful, Database.AllowsCallouts{
global Database.QueryLocator start(Database.BatchableContext bc) {
return gAllRecords();
public Database.QueryLocator gAllRecords(){
try{
//Create fieldset on Object and get fields in SOQL query, BankFieldSet this fieldset name on bank object
String queryString = 'Select Id';
for(Schema.FieldSetMember fieldMember : sObjectType.Bank__c.FieldSets.BankFieldSet.getFields()){
queryString += ', '+fieldMember.getFieldPath();}
system.debug('queryString@@@'+queryString);
queryString+=' FROM Bank__c WHERE isActive__c =true AND Location__c=\'Noida\' AND IsNeeded__c= true AND Status__c IN (\'Failed\',\'Unsuceess\') LIMIT '+Integer.valueOf(Label.LabelName);
return Database.getQueryLocator(queryString);
}catch(Exception ex){
ErrorLog__c log = new ErrorLog__c();
log.Message__c = ex.getLineNumber()+' : '+ex.getMessage();
insert log;}
return null;}
global void execute(Database.BatchableContext bc, List<Bank__c> lstofbank){}
global void finish(Database.BatchableContext bc){}
Comments
Post a Comment