global class TrackConsumableSalesDailyBatch implements Database.Batchable<sObject> {
|
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<TrackConsumableSalesForecast__c> scope) {
|
List<TrackConsumableSalesForecast__c> UpdateList = new List<TrackConsumableSalesForecast__c>();
|
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) {
|
|
}
|
|
}
|