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
Chinni reddyChinni reddy 

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

Hi,

I am executing Batch Apex this type of error showing can you please solve my problem
(Line: 2, Column: 10
Method does not exist or incorrect signature: void executeBatch(BatchApexExample) from the type Database.
this is my code:

global class BatchApexExample implements DataBase.Batchable<sObject>
{
    global String query = 'oppartunaty';
  global DataBase.QueryLocator start(DataBase.BatchableContext bc)
    {
        
        string query='select id,name,amount, Discription from oppartunaty';
        return Database.getQueryLocator(query);
    }
        
     global void execute(DataBase.BatchableContext bc, List<oppartunaty> records){
    
        
        for(oppartunaty  opp: records)
        {
            opp.amount=2000;
            opp.Discription='this my first batch Apex';
                
        }
         update records;
       
        // process each 
    }
    global void finish(Database.BatchableContext bc){
        //procee    
    }
     
}
ASIF ALIASIF ALI
This is the sample example of Batch Apex,
You can relate your code with it,
It will help you a lot;
global class UpdateAllOpportunity implements Database.Batchable<sObject>,Database.Stateful
{
global Integer recordsProcessed = 0;
string query;
global Database.querylocator start(Database.BatchableContext BC)
{
Query = 'Select id, name,StageName From Opportunity';
system.debug('Prosessing');
return Database.getQueryLocator(query);

}

global void execute(Database.BatchableContext BC, List<Opportunity> scope1)
{
list<opportunity> oppoList = new list<opportunity>();
for(Opportunity p : Scope1)
{
if(p.Name != 'test')
{
p.stageName= 'close won';
recordsProcessed = recordsProcessed + 1;

} 
oppoList.add(p); 

} 
update oppoList; 

}

global void finish(Database.BatchableContext BC)
{
AsyncApexJob a = [Select Id, Status from AsyncApexJob where Id =:BC.getJobId()];
system.debug(recordsProcessed + 'Prosessed Records');
system.debug(a);

}
}

 
Deepali KulshresthaDeepali Kulshrestha
Hi Chinni,

Greetings to you!

I have fixed the error in your code. Now you can use this code.
 
global class BatchApexExample implements DataBase.Batchable<sObject>
{
    global String query = 'oppartunaty';
  global DataBase.QueryLocator start(DataBase.BatchableContext bc)
    {
        
        string query='select id,name,amount, Description from opportunity';
        return Database.getQueryLocator(query);
    }
        
     global void execute(DataBase.BatchableContext bc, List<opportunity> records){
    
        
        for(opportunity  opp: records)
        {
            opp.amount=2000;
            opp.Description ='this my first batch Apex';
                
        }
         update records;
       
        // process each 
    }
    global void finish(Database.BatchableContext bc){
        //procee    
    }
     
}


​​​​​​​I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha.
Ajay K DubediAjay K Dubedi
Hi Chinni reddy,

Please update your code as following code. I have tested in my org and it is working perfectly fine. There was a problem of spelling of 'Opportunity' object and its fields in your code.
  
  
global class BatchApexExample implements DataBase.Batchable<sObject>
{
    global String query = 'opportunity';
    global DataBase.QueryLocator start(DataBase.BatchableContext bc)
    {
        
        string query='select id,name,Amount, Description from opportunity';
        return Database.getQueryLocator(query);
    }
    
    global void execute(DataBase.BatchableContext bc, List<opportunity> records){
        
        
        for(opportunity  opp: records)
        {
            opp.amount=2000;
            opp.Description='this my first batch Apex';
            
        }
        update records;
        
        // process each 
    }
    global void finish(Database.BatchableContext bc){
        //procee    
    }
    
}



I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks,
Ajay Dubedi
Chinni reddyChinni reddy
Thanks Madam/Sir 
It is very help full to me 
Shanu Kumar 18Shanu Kumar 18
Hi Chinni,
which one is correct. please mark the correct one as Best Answer.
Thanks!