+ Start a Discussion
sai kumar 433sai kumar 433 

please write test class for this thanx adv?

global class BatchAapex1 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)
       List<Account> acc = new List<Account>();
       for(Account a:acc)
           a.name = 'Mr.' +a.name;
       update acc;
     global void finish(Database.BatchableContext bc)
Nayana KNayana K
private class UpdateAccNameTest {

    static testmethod void test() {
        Account objAcc = new Account(Name = 'Some Name', BillingState = 'AP', BillingStreet='Tst', BilllingCity='test city',
									BillingCountry='USA', BillingPostalCode='12345');
		insert objAcc;

       Database.executeBatch(new BatchAapex1());
		// verify the result
       System.assertEquals('Mr.Some Name',[SELECT Name FROM Account WHERE Id=: objAcc.Id].Name);

Please mark this as solved.
Vasani ParthVasani Parth
++ .  I think you need to read below link it helps you