I have this Apex batch having issues with call. I am new in this apex-world. Can someone help me out. My code is here.
global class Samplelotinactive implements Database.Batchable<Sample_Lot_vod__c>
{
Public String query;
Public String email;
global Database.QueryLocator start(Database.BatchableContext BC)
{
query = 'SELECT ID,Active_vod__c FROM Sample_Lot_vod__c where Expiration_Date_vod__c=NEXT_N_DAYS:60 and Active_vod__c=true'; //need to define query
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Sample_Lot_vod__c> m)
{
List<Sample_Lot_vod__c> m1 = [SELECT ID,Active_vod__c FROM Sample_Lot_vod__c where Expiration_Date_vod__c=NEXT_N_DAYS:60 and Active_vod__c=true];
for (Sample_Lot_vod__c s: m){
s.Active_vod__c=false;
}
update m;
}
global void finish(Database.BatchableContext BC)
{
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(new String[]{email});
mail.setReplyTo('saikatkumarneogy@gmail.com');
mail.setSenderDisplayName('Batch Processing Completed');
mail.setPlainTextBody('Sample lots inactivated');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
}
}
Best Answer
Database.Batchable nominally supports parameterised types (using the
<>
notation) but it appears that when returning Database.QueryLocator rather Iterable from thestart
method you have to stick to<SObject>
.(Note that returning Database.QueryLocator rather than Iterable from the
start
method usually gives better performance and allows the batchable to process up to 50 million records rather than hitting a governor limit at 50,000 records.)This will compile and execute: