global class ProRegisterBatch implements Database.Batchable<sObject> {
|
String regId;
|
|
global ProRegisterBatch(String regId) {
|
this.regId = regId;
|
}
|
|
global ProRegisterBatch() {
|
|
}
|
|
global Database.QueryLocator start(Database.BatchableContext BC) {
|
Date yesterday = Date.Today() - 1;
|
|
if (String.isBlank(this.regId)) {
|
return Database.getQueryLocator([select id, ValidProductRegister__c
|
from Product_Register__c
|
where ValidProductRegister__c = false
|
and ValidTo__c = yesterday ]);
|
|
} else {
|
if (this.regId == 'updateAllInvalidData') {
|
return Database.getQueryLocator([select id, ValidProductRegister__c
|
from Product_Register__c
|
where ValidProductRegister__c = false ]);
|
|
} else {
|
return Database.getQueryLocator([select id, ValidProductRegister__c
|
from Product_Register__c
|
where id = :this.regId
|
and ValidTo__c <= :Date.Today()]);
|
}
|
|
}
|
}
|
|
global void execute(Database.BatchableContext BC, List<Product_Register__c> dcList) {
|
|
if (dcList.size() > 0) update dcList;
|
}
|
|
global void finish(Database.BatchableContext BC) {
|
|
}
|
}
|