Below is the sample code which I have tested in my org and it is working fine. Kindly modify the code as per your requirement.
global class Batch_UpdateStatus implements Database.Batchable<sObject >{
global Database.queryLocator start(Database.BatchableContext bc){
return Database.getQueryLocator('Select Id, Status__c from Opportunity where Status=\'Draft\' AND LastModifiedDate = LAST_N_DAYS:2');
}
global void execute(Database.BatchableContext bc, List<Opportunity > scope){
List<Opportunity> oppLst = new List<Opportunity>();
for(Opportunity opp : scope){
opp.Status__c = 'Submitted';
oppLst.add(opp);
}
UPDATE oppLst;
}
global void finish(Database.BatchableContext bc){
}
}
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Hi Khan Anas, in finish method i have to write code for email i.e., whenever batch job is completed we need to get the email saying no of records success and no of records failed. How can this be done?
Greetings to you!
Below is the sample code which I have tested in my org and it is working fine. Kindly modify the code as per your requirement.
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
Regards,
Khan Anas