0
global class BatchTest implements Database.Batchable<SObject>{

    global Integer recordsProcessed = 0;

    global Database.QueryLocator start(Database.BatchableContext BC){
        return Database.getQueryLocator('SELECT Active__c,AnnualRevenue,Name,Phone FROM Account');
    }

    global void execute(Database.BatchableContext BC, List<Insert_c> scope){
        List<Insert_c> insertData = new List<Insert_c>();
        for(Insert_c I : scope){
            I.Name = scope.Name;
            I.Annual_Revenue__c = scope.AnnualRevenue;
            I.Test__c = scope.Active__c;
            I.Mobile__c = scope.Phone;
            recordsProcessed = recordsProcessed + 1;
            insertData.add(I);
        }
        insert insertData;
        system.debug('record Inserted'+recordsProcessed);
    }
    global void finish(Database.BatchableContext BC){
        AsyncApexJob job = [SELECT Id, Status, NumberOfErrors, 
                            JobItemsProcessed,
                            TotalJobItems, CreatedBy.Email
                            FROM AsyncApexJob
                            WHERE Id = :bc.getJobId()];
        // call some utility to send email
        EmailUtils.sendMessage(job, recordsProcessed);
    }
}

Having above error, please help here

1
  • 1
    N.B. unless building a managed package; you don't need global modifiers; use public
    – cropredy
    Mar 2, 2020 at 19:46

2 Answers 2

2

Just update the execute method signature to this.

global void execute(Database.BatchableContext BC, List<SObject> scope){
    //....
}

Whatever object you mention while implementing the interface, the same type you need to define with the scope in the execute method.

global class BatchTest implements Database.Batchable<SObject>{
//....
}
0

You mentioned the wrong object name in the parameter it should be List<Insert__c> global void execute(Database.BatchableContext BC, List<Insert__c> scope)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .