You need to sign in to do that
Don't have an account?

Bacth test class error
@istest
private class Accountupdate {
@istest
static void tetslead(){
List<Account> l= new List<Account>();
Account a= new Account();
a.Name='surya';
a.Phone='123';
l.add(a);
insert l;
Test.startTest();
Accountupdate ap= new Accountupdate();
Id jobid= Database.executeBatch(ap);
Test.stopTest();
}
}
class
global class Accountupdate implements Database.Batchable<sObject>
{
global Database.QueryLocator start(Database.BatchableContext BC)
{
String query = 'SELECT Id,Name,Phone FROM Account ';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Account> scope)
{
for ( Account a : scope)
{
a.Phone='123';
}
update scope;
}
global void finish(Database.BatchableContext BC)
{
}
}
I am getting below error

private class Accountupdate {
@istest
static void tetslead(){
List<Account> l= new List<Account>();
Account a= new Account();
a.Name='surya';
a.Phone='123';
l.add(a);
insert l;
Test.startTest();
Accountupdate ap= new Accountupdate();
Id jobid= Database.executeBatch(ap);
Test.stopTest();
}
}
class
global class Accountupdate implements Database.Batchable<sObject>
{
global Database.QueryLocator start(Database.BatchableContext BC)
{
String query = 'SELECT Id,Name,Phone FROM Account ';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Account> scope)
{
for ( Account a : scope)
{
a.Phone='123';
}
update scope;
}
global void finish(Database.BatchableContext BC)
{
}
}
I am getting below error
Change your test class (Class Name) from AccountUpdate to Something else like AccountUpdateTest (Like below). It gives you error as it finds conflict between Actual batch class name and test class name as the same.
Hope this helps! Please mark as best answer if it does
Thanks,
Sarvani