About this question
I am writing a batch class which will get the records whose status picklist value is 'no response' and whose created date is before greater than or equal to 48 hrs and update the status to 'declined'.
Do I need to use Database.stateful here ?
global class SolicitaBatch implements Database.Batchable{ String query;
String email;
Id toUserId;
Id fromUserId;
global Database.QueryLocator start(Database.BatchableContext BC)
{
Datetime dtime = datetime.now().addhours(-48);
String query = 'select id,createdDate, Status__c from Solicitation__C where createdDate <= :dtime and Status__c = 'No Response' ';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, Listscope){ ListSols = new List for(Solicitation__C s : scope)();
{
s.Status__c = 'ABCD';
}
update scope;
}
global void finish(Database.BatchableContext BC)
{
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(new String[] {email});
mail.setReplyTo('batch@acme.com');
mail.setSenderDisplayName('Batch Processing');
mail.setSubject('Batch Process Completed');
mail.setPlainTextBody('Batch Process has completed');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}