0
global class Batch_example_1 implements Database.Batchable<sObject>{
    global Database.QueryLocator start(Database.BatchableContext bc){
        //fetch all the accounts
       String query='select id,Name,ownership,type from Account';
        return Database.getQueryLocator(query);
    }
    //update the values of ownership and rating
    global void execute(Database.BatchableContext bc,List<Account>scope){
        for(Account a: scope){
            a.Ownership='Public';
            a.rating='hot';
         }
        update scope;
    }
    global void finish(Database.BatchableContext bc){
        AsyncApexJob jb=[select id, JobType,TotalJobItems,JobItemsProcessed,NumberOfErros from AsyncApexJob where id=:bc.getjobId()] ;
        Messaging.singleEmailMessage msg=new Messaging.Singleemailmessage();
        String[] toadd=new String[]{'salesforcebatch300@gmail.com'};
        msg.settoAddresses(toadd);
        String body='Dear Admin,<br/> Batch operation with JobId :<b>'+jb.Id;
        body=body+'</b><br/><br/>Processed Successfully <br/> Total JobItems:<b>'+jb.totalJobItems;
        body=body+'</b><br/><br/> No of Erros:<b>'+jb.NumberOfErrors+'</b>';
        msg.setSubject('Batch Status');
        msg.setHtmBody(body);
        Messaging.Email[] emails =new Messaging.Email[]{msg};
        Messaging.sendEmail(emails);
    } 
}

Error

on line 1 Class Batch_example_1 must implement the method: void Database.Batchable<SObject>.execute(Database.BatchableContext, List<SObject>)

one line 8 global methods do not support parameter type of List<Account>

5
  • 1
    do you also have a class named as List somewhere? May 30 at 21:15
  • @PranayJaiswal List is a reserved keyword, actually, but you were on the right path.
    – sfdcfox
    May 30 at 21:40
  • Two comments here: 1. This probably does not need to be global. 2. Strictly speaking, the type against the generic base class, you have sObject, should be the same as the type for the scope it, you have Account (though Apex does not enforce this).
    – Phil W
    May 30 at 21:42
  • @PhilW As I stated, List is a reserved keyword. It's the Account that's the problem.
    – sfdcfox
    May 30 at 21:43
  • @sfdcfox, only saw your comment after submitting mine. Will adjust.
    – Phil W
    May 30 at 21:44
1

You have a class called Account in your org. It's causing this code to fail to compile (and likely other code in your org as well). You should consider refactoring the Account class to be called something that won't conflict with code. To fix the immediate problem, use Schema.Account.

global void execute(Database.BatchableContext bc, List<Schema.Account> scope){

This will resolve both compile errors. You'll also need to change every reference in your code from Account to Schema.Account.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.