function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
niharnihar 

I have return a batch class but it is showing errors can anyone suggest me

Error : Class sendemail must implement the method: void Database.Batchable<SObject>.execute(Database.BatchableContext, List<SObject>)

my batch class :
global class sendemail implements Database.Batchable <sobject> {
global Database.QueryLocator start(Database.BatchableContext bc) {
        String Query;
        Query = 'SELECT Name,Id From Opportunities WHERE CloseDate = Tommorow';
        return Database.getquerylocator(Query);
        }
global void execute(Database.BatchableContext bc, List<Opportunities> opplist) {
        for(Opportunities opp :opplist){
        opp.CloseDate = 'Tommorow'; 
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        email.setToAddresses(new String[] {'nihar.annamaneni@gmail.com'});
        email.setSubject('opportunity closed date');
        email.setPlainTextBody('Dear user, Your opportunity is closed date is tommorow');
        emails.add(email);
        }
        Messaging.sendEmail(emails);
        update opplist;
        }
global void finish(database.BatchableContext bc){
        }
}
Best Answer chosen by nihar
Venkateswarlu PVenkateswarlu P
global class sendmail implements Database.Batchable<sobject> {
	global Database.QueryLocator start(Database.BatchableContext bc) {        
        String Query = 'select name,StageName,CloseDate from Opportunity';
        return Database.getquerylocator(Query);
    }
	global void execute(Database.BatchableContext bc, List<Opportunity> opplist){
        for(Opportunity opp :opplist){
        	opp.CloseDate = system.today()+1;
        }
     update opplist;
}
global void finish(database.BatchableContext bc){
    Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();        		
    message.setToAddresses (new String[] {'venkat.pattabhi@gmail.com'});                
    message.setsubject('opportunity closed date');
    string body='Dear user, Your opportunity is closed date is tommorow';
    message.setPlainTextBody(body);
    Messaging.Email[] emails=new Messaging.Email[]{message};
    Messaging.sendEmail(emails);    
	}
}
Try like this.let me know if any modifications are required.
 

All Answers

Venkateswarlu PVenkateswarlu P
1. Normally we will do all the post bach operation Like ..Email sending in finish Method.
2. you can't assign string to CloseDate. opp.CloseDate = 'Tommorow'; 
3. Send the actual requirement.
Venkateswarlu PVenkateswarlu P
global class sendmail implements Database.Batchable<sobject> {
	global Database.QueryLocator start(Database.BatchableContext bc) {        
        String Query = 'select name,StageName,CloseDate from Opportunity';
        return Database.getquerylocator(Query);
    }
	global void execute(Database.BatchableContext bc, List<Opportunity> opplist){
        for(Opportunity opp :opplist){
        	opp.CloseDate = system.today()+1;
        }
     update opplist;
}
global void finish(database.BatchableContext bc){
    Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();        		
    message.setToAddresses (new String[] {'venkat.pattabhi@gmail.com'});                
    message.setsubject('opportunity closed date');
    string body='Dear user, Your opportunity is closed date is tommorow';
    message.setPlainTextBody(body);
    Messaging.Email[] emails=new Messaging.Email[]{message};
    Messaging.sendEmail(emails);    
	}
}
Try like this.let me know if any modifications are required.
 
This was selected as the best answer