+ Start a Discussion
Peter McGavinPeter McGavin 

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

Hi,

I keep getting the following compile error:

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

FYI, here is my class code:

global class LeadProcessor implements Database.Batchable<Sobject>
    {    

    global Database.QueryLocator start(Database.BatchableContext bc) 
    {
        return Database.getQueryLocator([SELECT LeadSource FROM Lead]);
    }

    global void execute(Database.BatchableContext bc, List<Leads> scope){
        // process each batch of records
        for (Leads l: scope) {
             l.LeadSource = 'Dreamforce';
             recordsProcessed = recordsProcessed + 1;
            }
        update scope;
    }    

    global void finish(Database.BatchableContext bc){}    
}

Please assist. Thanks

 
Best Answer chosen by Peter McGavin
Amit Chaudhary 8Amit Chaudhary 8
Varible recordsProcessed  is not defined,

Please update your code like below
global class LeadProcessor implements    Database.Batchable<Sobject> 
{
    global Database.QueryLocator start(Database.BatchableContext bc) 
    {
        return Database.getQueryLocator([Select LeadSource From Lead ]);
    }

    global void execute(Database.BatchableContext bc, List<Lead> scope)
    {
            for (Lead Leads : scope) 
            {
                Leads.LeadSource = 'Dreamforce';
            }
        update scope;
    }    

    global void finish(Database.BatchableContext bc){   }    
}
Please check below post for same issue
1) https://developer.salesforce.com/forums/?id=906F0000000D9AUIA0

Let us know if this will help you
 

All Answers

Amit Chaudhary 8Amit Chaudhary 8
Varible recordsProcessed  is not defined,

Please update your code like below
global class LeadProcessor implements    Database.Batchable<Sobject> 
{
    global Database.QueryLocator start(Database.BatchableContext bc) 
    {
        return Database.getQueryLocator([Select LeadSource From Lead ]);
    }

    global void execute(Database.BatchableContext bc, List<Lead> scope)
    {
            for (Lead Leads : scope) 
            {
                Leads.LeadSource = 'Dreamforce';
            }
        update scope;
    }    

    global void finish(Database.BatchableContext bc){   }    
}
Please check below post for same issue
1) https://developer.salesforce.com/forums/?id=906F0000000D9AUIA0

Let us know if this will help you
 
This was selected as the best answer
Peter McGavinPeter McGavin
Thanks Amit. 
Hariom kankerwal 7Hariom kankerwal 7
Hi All, Please assit,

i keep getting below error,

1.Class Opty_Currency_Update must implement the method: void Database.Batchable<SObject>.execute(Database.BatchableContext, List<SObject>)
2.global methods do not support parameter type of List<Opportunity>
my class code
:
global class Opty_Currency_Update implements Database.Batchable<Sobject> ,Database.Stateful{
    
    global Database.QueryLocator start(Database.BatchableContext bc){
       String query = 'select Id, Amount, INRValue__c from Opportunity';
        return Database.getQueryLocator(query);
    }
   
    global void execute(Database.BatchableContext bc, List<Opportunity> optyList){
        Http p = new Http();
        HttpREquest request = new HttpRequest();
        string endPoint = 'http://api.currencylayer.com/live';
        endPoint=endpoint+'access_key='+apiKey;
        endPoint=endPoint+'&currencies=INR&source=USD&format=1';
        request.setEndpoint(endpoint);
        request.setMethod('GET');
        HttpREsponse responce = p.send(request);
        String jsonString= response.getBody();
        System.JSONParser jp=JSON.createParser(jsonString);
        Decimal inrValue;
        while(jp.getText()!=null){
            if(jp.getText()=='USDINR'){
                jp.nextToken();
                inrValue=(Decimal)jp.getDecimalValue();
            }
        }
        for(Opporttunity op:optyList){
            op.INRValue__c = 'Rs'+(op.amount*inrValue);
        }
        update optyList;
    }
    global void finish(Database.BatchableContext bc){
        AsyncApexJob job =[select id,Status from AsyncApexjJob where Id =:bc.getJobId()];
        Messaging.SingleEmailMessage msg = new Messaging.SingleEmailMessage();
        string[] toadd=new string []{'hariom.sfdc@gmail.com'};
        msg.setToAddresses(toAdd);
        msg.setSubject('Intergration First Programm');
        msg.setPlainTextBody('Batch operation Processed :'+job.status);
        Messaging.Email[] emails = new Messaging.Email[]{msg};
        Messaging.sendEmail(emails);    
    }               
}


anony code

String apiKey ='5d35e4d851ea10c97a4621db93d9bc32';
Opty_Currency_Update op = new Opty_Currency_Update(apikey);
Database.executeBatch(op);

error:

Line: 2, Column: 27
Constructor not defined: [Opty_Currency_Update].<Constructor>(String)

Thanks