global Class Batchsample implements Database.Batchable<Attendance__c>{
global Database.QueryLocator start(Database.BatchableContext BC){
String Query = 'select id,Login_Date_c,Leave_Type__c from Attendance__c where Login_Date__c = LAST_N_DAYS:35 AND Leave_Type__c not in (SL,EL,AL,Half Day)';
return Database.getQueryLocator(Query);
}
global void execute(Database.BatchableContext BC,list<Attendance__c> scope){
Integer size = scope.size();
for(Integer i=0; i< size; i++)
{
del.add(i);
}
delete del;
}
global void finish(Database.BatchableContext BC){
}
}
Add a comment
|
1 Answer
It's a weird behavior with the compiler. Change it to Database.Batchable<sObject>
instead.
Notes:
- You don't need to copy the list before deleting it.
- Use an inline query.
- Don't query fields you don't need.
global Class Batchsample implements Database.Batchable<sObject>{
global Database.QueryLocator start(Database.BatchableContext BC){
return Database.getQueryLocator([
select id from Attendance__c
where Login_Date__c = LAST_N_DAYS:35 AND
Leave_Type__c not in ('SL','EL','AL','Half Day')
]);
}
global void execute(Database.BatchableContext BC,list<Attendance__c> scope){
delete scope;
}
global void finish(Database.BatchableContext BC){
}
}