global class TrackConsumableSalesDailyBatch implements Database.Batchable { public String query; public String tcsfid; global TrackConsumableSalesDailyBatch() { this.query = query; } global TrackConsumableSalesDailyBatch(String tcsfid) { this.query = query; this.tcsfid = tcsfid; } global Database.QueryLocator start(Database.BatchableContext bc) { query = 'SELECT id,OwnerId,Hospital__r.ET_owner__c,Hospital__r.ET_owner__r.IsActive FROM TrackConsumableSalesForecast__c WHERE TCSOwner__c = false'; if (tcsfid !=null) { query += ' and id = :tcsfid'; } return Database.getQueryLocator(query); } global void execute(Database.BatchableContext BC, list scope) { List UpdateList = new List(); for(TrackConsumableSalesForecast__c tcsf :scope){ TrackConsumableSalesForecast__c upDatetcsf = new TrackConsumableSalesForecast__c(); upDatetcsf.id = tcsf.id; if (tcsf.Hospital__r.ET_owner__r.IsActive == true) { upDatetcsf.OwnerId = tcsf.Hospital__r.ET_owner__c; UpdateList.add(upDatetcsf); } } if(!UpdateList.isEmpty()){ update UpdateList; } } global void finish(Database.BatchableContext BC) { } }