Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Salesforce by (11.9k points)

I am currently using the Apex Workbook to refresh my knowledge of SalesForce.

Tutorial #15, Lesson 1: Offers the following code:

global class CleanUpRecords implements Database.Batchable<Object>

{

    global final String query;

    global CleanUpRecords (String q) {query = q;}

    global Database.Querylocator start (Database.BatchableContext BC)

    {

           return Database.getQueryLocator(query);

    }    

    global void execute (Database.BatchableContext BC, List<sObject> scope)

    {

        delete scope;

        Database.emptyRecycleBin(scope);

    }    

    global void finish(Database.BatchableContext BC)

    {

        AsyncApexJob a = [

                SELECT Id, Status, NumberOfErrors, JobItemsProcessed, TotalJobItems, CreatedBy.Email

                FROM AsyncApexJob 

                WHERE Id = :BC.getJobId()

            ];

        // Send an email to the Apex job's submitter

        // notifying of job completion.

        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

        String[] toAddresses = new String[] {a.CreatedBy.Email};

        mail.setToAddresses(toAddresses);

        mail.setSubject('Record Clean Up Completed ' + a.Status);

        mail.setPlainTextBody (

                'The batch Apex job processed ' + a.TotalJobItems +

                ' batches with '+ a.NumberOfErrors + ' failures.'

               );

        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

    }

}

However, regardless of which development interface (e.g. Force IDE, console, setup) I use, when I try to save this, I get:

Multiple markers at this line

    - File only saved locally, not to server

    - Save error: CleanUpRecords: Class must implement the global interface method: Iterable<Object> start(Database.BatchableContext) from Database.Batchable<Object>, CleanUpRecords: Class must implement the global interface method: void execute(Database.BatchableContext, LIST<Object>) from 

     Database.Batchable<Object>

(Or some equivalent, depending upon how I try to save it.)

However, it seems to me the required methods are already there.

What's missing?

1 Answer

0 votes
by (32.1k points)
edited by

Your class declaration should be:

global class CleanUpRecords implements Database.Batchable<sObject> {

instead of:

global class CleanUpRecords implements Database.Batchable<Object> {

Looking for a comprehensive Salesforce course? Enroll now! 

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...