Simple Batch Apex example in Salesforce

Simple Batch Apex example in Salesforce

Apex Code:
global class batchAccountUpdate implements Database.Batchable<sObject> {
 
    global Database.QueryLocator start( Database.BatchableContext BC ) {
 
        String query = ‘SELECT Id,Name FROM Account’;
        return Database.getQueryLocator( query );
 
    }
   
    global void execute( Database.BatchableContext BC, List< Account > scope ) {
 
         for ( Account a : scope ) {
             a.Name = a.Name + ‘Updated’;            
         }
         update scope;
 
    }   
    
    global void finish( Database.BatchableContext BC ) {
    }
 
}

Run the batch apex for testing it in Developer Console.

Output:

Leave a Reply