+ Start a Discussion
Hari nadh babu EluruHari nadh babu Eluru 

Running Batch in Execute Anonymous but throwing error: Method does not exist or incorrect signature: void executeBatch(UpdateGender, Integer) from the type Database

Hi all, I did this batch apex code.
public class UpdateGender {
    
    public database.querylocator start(database.batchableContext abc){
        string a = 'SELECT Student_Id__c, Name, Gender__c FROM Student__c';
        return database.getquerylocator(a);
    }
    
    public void execute(database.batchableContext def, list<Student__c> x){
        for(Student__c a : x){
            if(a.Gender__c == 'Male'){
                a.Name = 'Mr'+a.Name;
            }
            else if(a.Gender__c == 'Female'){
                a.Name = 'Mrs'+a.Name;
            }
        }
        update x;
    }
    
    public void finish(database.batchableContext ghi){
        system.debug('Finish::!');
    }
}
I wrote executed code in anonymous windows is as follows above
UpdateGender obj = new UpdateGender();
database.executeBatch(obj,10);
While i'm executing this batch in anonymous window they were showing error as below image
error
Please resolve my issue problem. Thank you to all
Best Answer chosen by Hari nadh babu Eluru
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Hari nath,

Below is the syntax for the batch class. I done see you are implementing Database.Batchable interface. Can you try modifying it.
 
global class MyBatchClass implements Database.Batchable<sObject> {
    global (Database.QueryLocator | Iterable<sObject>) start(Database.BatchableContext bc) {
        // collect the batches of records or objects to be passed to execute
    }
    global void execute(Database.BatchableContext bc, List<P> records){
        // process each batch of records
    }    
    global void finish(Database.BatchableContext bc){
        // execute any post-processing operations
    }    
}

If this solution helps, Please mark it as best answer.

Thanks,
 

All Answers

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Hari nath,

Below is the syntax for the batch class. I done see you are implementing Database.Batchable interface. Can you try modifying it.
 
global class MyBatchClass implements Database.Batchable<sObject> {
    global (Database.QueryLocator | Iterable<sObject>) start(Database.BatchableContext bc) {
        // collect the batches of records or objects to be passed to execute
    }
    global void execute(Database.BatchableContext bc, List<P> records){
        // process each batch of records
    }    
    global void finish(Database.BatchableContext bc){
        // execute any post-processing operations
    }    
}

If this solution helps, Please mark it as best answer.

Thanks,
 
This was selected as the best answer
Hari nadh babu EluruHari nadh babu Eluru
@Sai Praveen. Thank you !