• vijay T 37
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
 This is Batch Class 
global class BatchAccountDescUpdate implements Database.Batchable<sObject> {
    global Database.QueryLocator start(Database.BatchableContext BC){
        String query = 'SELECT description FROM Account';
        return Database.getQueryLocator(query);
        
        //Even we can write like below also
        //return Database.QueryLocator('SELECT description FROM Account')
    }
    global void execute(Database.BatchableContext BC, List<Account> scope){ 
        
        for(Account a: scope){
            if(a.description == 'Not Available'){
               a.Description = 'Please fill details, else record will be made inactive!';
              
            }
            Update scope;       
        }
    }  
    global void finish(Database.BatchableContext BC){
        //code for sending email
        //calling another batch 
        //sending state of processing records ** using stateful 
    }

}

Below is my Test Class
@isTest
public class BatchAccountDescUpdateTest
{
    static testMethod void testMethod1()
    {
        List<Account> lstAccount = new List<Account>();
        for(Integer i=0 ;i <200;i++)
        {
            Account acc = new Account();
            if(acc.description == 'Not Available'){
               acc.description = 'Please fill details, else record will be made inactive!';
             }
            lstAccount.add(acc);
        }
       
        insert lstAccount;
       
        Test.startTest();

            BatchAccountDescUpdate obj = new BatchAccountDescUpdate();
            DataBase.executeBatch(obj);
           
        Test.stopTest();
    }
}