Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I save this SalesForce Batchable class?

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?

like image 911
Brian Kessler Avatar asked Dec 28 '22 04:12

Brian Kessler


1 Answers

Prepare to be frustrated ... there's just one character off.

Your class declaration should be:

global class CleanUpRecords implements Database.Batchable<sObject> {

instead of:

global class CleanUpRecords implements Database.Batchable<Object> {
like image 184
barelyknown Avatar answered Jan 18 '23 23:01

barelyknown