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
sai kumar 433sai kumar 433 

please execute this test class code coverage......

global class BatchClass2 implements Database.Batchable<sObject>{
   global final String Query;
   global final String Entity;
   global final String Field;
   global final String Value;

   global BatchClass2(String q, String e, String f, String v){
             Query=q; Entity=e; Field=f;Value=v;
   }

   global Database.QueryLocator start(Database.BatchableContext BC){
      return Database.getQueryLocator(query);
   }

   global void execute(Database.BatchableContext BC, 
                       List<sObject> scope){
      for(Sobject s : scope){s.put(Field,Value); 
      }      update scope;
   }

   global void finish(Database.BatchableContext BC){

   }

}

test class


@isTest
public class BatchClass_Test2 
{
    static testMethod void test() {
        Database.QueryLocator QL;
        Database.BatchableContext BC;
        List<Account> AcctList = new List<Account>();
        BatchClass2 AU = new BatchClass2('Name', 'Test');
        QL = AU.start(bc);
        
        Database.QueryLocatorIterator QIT =  QL.iterator();
        while (QIT.hasNext())
        {
            Account Acc = (Account)QIT.next();            
            System.debug(Acc);
            AcctList.add(Acc);
        }        
        
        AU.execute(BC, AcctList);
        AU.finish(BC);        
    }
}
Nayana KNayana K
@isTest
public class BatchClass_Test2 
{
    static testMethod void test() {
        Database.QueryLocator QL;
        Database.BatchableContext BC;
        List<Account> AcctList = new List<Account>{new Account(Name = 'Test'),new Account(Name='Test2')};
		insert AcctList;
		
		Test.startTest();
        Database.executeBatch(new BatchClass2('SELECT Id,Name FROM Account','Account','Name', 'Test Changed'));
        Test.stopTest();
		
		// verify the result
		List<Account> lstAccToVerify = new List<Account>([SELECT Name FROM Account]);
		for(Account objAcc : lstAccToVerify)
			System.assertEquals('Test Changed',objAcc.Name);       
    }
}

 
sai kumar 433sai kumar 433
can you please share your emailid any doubts is there i will message you