• deva nalisetti
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
global class batch_example implements Database.Batchable<sobject> {
    global Database.QueryLocator start (Database.BatchableContext bc){
       return Database.getQueryLocator('select id,closeDate,StageName from Opportunity where StageName!=:closed Won'); 
    } 
    global void execute(Database.BatchableContext bc,list<opportunity>scope){
        for(opportunity op:scope){
            op.closeDate=system.today();
        }
        update scope;
    }
    global void finish (Database.batchableContext bc){
        Messaging.SingleEmailMessage email1=new Messaging.SingleEmailMessage();
        string[]toadd=new string[]{'ora0423.nallisetti@gmail.com'};
            email1.setToAddresses(toadd);
        email1.setSubject('batch completion Alert');
        email1.setplainTextBody('Batch job'+bc.getJobId()+ 'is processed successfully');
        Messaging.Email[]emails=new Messaging.Email[]{email1} ;
          Messaging.sendEmail(emails);
    
    }
}