function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
john4sfdcjohn4sfdc 

How do run the batch class in annonoymus apex

Can anybody help me in executing the below batch class using annonomous apex

 

global class batchUpdateAccounts implements Database.Batchable<sObject>,Database.Stateful{

global Database.QueryLocator start(Database.BatchableContext bc){

    return database.getQuerylocator('select id,Category__c,Family__c from Account');
}

global void execute(Database.BatchableContext bc, List<SObject> scope) {
    
        List<Account> accs = (List<Account>)scope;
        List<Account> accsToUpdate = new List<Account>();
        List<Global_families__c> gfslst = new List<Global_families__c>();
        gfslst = [select Is_Global__c, Name from Global_families__c];
 
        for(Account acunts : accs){
        for(Global_families__c lstglobal: gfslst ){
        if(acunts.Family__c == lstglobal.Name && lstglobal.Is_Global__c == TRUE){
        Acunts.Family__c = 'Global';
        accsToUpdate.add(acunts);
        }
        }
        }
        
        update accsToUpdate;
        
       
}

global void finish(Database.BatchableContext bc){
        

}

}

john4sfdcjohn4sfdc

I have tried to run the below code but it throws me an error saying incorrect signature

 

batchUpdateAccounts objTest = new batchUpdateAccountst();
Database.executebatch(objTest);

sfdcfoxsfdcfox
You didn't include a "scope" parameter. Try changing (objTest) to (objTest,50000000).
Mani_SFDCMani_SFDC

Try this out -)

 

batchUpdateAccounts objTest = new batchUpdateAccounts();
Database.executebatch(objTest,200);