You need to sign in to do that
Don't have an account?
The new Learner
constructor not defined in the test class
Hi Experts,
I wrote one batch class with contractor like below. but when i was try to run my test class i am getting an error that constructor is not defind. below is my test class as well , can anyone help me plesae . thanks in advance
private list<String> sOrganization;
public UpdateAccountCallList(String[] sorg) {
sOrganization = sorg;
}
Test class:
@isTest
public class AccountUpdatecallistBatchJobTest
{
static testMethod void testMethod1()
{
List<Account> lstAccount= new List<Account>();
List<Account> lstAccount1= new List<Account>();
List<Account> lstAccount2= new List<Account>();
List<Account> lstAccount3= new List<Account>();
List<Account> lstAccount4= new List<Account>();
List<Account> lstAccount5= new List<Account>();
for(Integer i=0 ;i <5;i++)
{
Account acc = new Account();
acc.Name =’Name’+i;
acc.Call_List_Frequency__c=8;
acc.Call_List__c=true;
acc.Call_List_Start_Date__c=system.today()-1;
acc.Call_List_Preferred_Day__c=’MOnday’;
date myDate = date.today();
acc.Call_List_Next_Preferred_Date__c=myDate.toStartofWeek()+0;
Account acc1 = new Account();
acc1.Name =’Name1’+i;
acc1.Call_List_Frequency__c=6.0;
acc1.Call_List__c=true;
acc1.Call_List_Start_Date__c=system.today()-1;
acc1.Call_List_Preferred_Day__c=’Tuesday’;
date myDate1 = date.today();
acc1.Call_List_Next_Preferred_Date__c=myDate1.toStartofWeek()+1;
lstAccount1.add(acc1);
Account acc2 = new Account();
acc2.Name =’Name1’+i;
acc2.Call_List_Frequency__c=6.0;
acc2.Call_List__c=true;
acc2.Call_List_Start_Date__c=system.today()+1;
acc2.Call_List_Preferred_Day__c=’Wednesday’;
date myDate2 = date.today();
acc2.Call_List_Next_Preferred_Date__c=myDate2.toStartofWeek()+2;
lstAccount2.add(acc2);
Account acc3 = new Account();
acc3.Name =’Name1’+i;
acc3.Call_List_Frequency__c=6.0;
acc3.Call_List__c=true;
acc3.Call_List_Start_Date__c=system.today()-1;
acc3.Call_List_Preferred_Day__c=’Thursday’;
date myDate3 = date.today();
acc3.Call_List_Next_Preferred_Date__c=myDate3.toStartofWeek()+3;
lstAccount3.add(acc3);
Account acc4 = new Account();
acc4.Name =’Name1’+i;
acc4.Call_List_Frequency__c=6.0;
acc4.Call_List__c=true;
acc4.Call_List_Start_Date__c=system.today()-1;
acc4.Call_List_Preferred_Day__c=’Friday’;
date myDate4 = date.today();
acc4.Call_List_Next_Preferred_Date__c=myDate4.toStartofWeek()+4;
lstAccount4.add(acc4);
Account acc5 = new Account();
acc5.Name =’Name1’+i;
acc5.Call_List_Frequency__c=6.0;
acc5.Call_List__c=true;
acc5.Call_List_Start_Date__c=system.today()-1;
acc5.Call_List_Preferred_Day__c=’None’;
acc5.Call_List_Next_Preferred_Date__c=system.today();
lstAccount5.add(acc5);
}
insert lstAccount;
insert lstAccount1;
insert lstAccount2;
insert lstAccount3;
insert lstAccount4;
insert lstAccount5;
Test.startTest();
UpdateAccountCallList obj = new UpdateAccountCallList();
obj.currentweek=9;
DataBase.executeBatch(obj);
Test.stopTest();
}
}
I wrote one batch class with contractor like below. but when i was try to run my test class i am getting an error that constructor is not defind. below is my test class as well , can anyone help me plesae . thanks in advance
private list<String> sOrganization;
public UpdateAccountCallList(String[] sorg) {
sOrganization = sorg;
}
Test class:
@isTest
public class AccountUpdatecallistBatchJobTest
{
static testMethod void testMethod1()
{
List<Account> lstAccount= new List<Account>();
List<Account> lstAccount1= new List<Account>();
List<Account> lstAccount2= new List<Account>();
List<Account> lstAccount3= new List<Account>();
List<Account> lstAccount4= new List<Account>();
List<Account> lstAccount5= new List<Account>();
for(Integer i=0 ;i <5;i++)
{
Account acc = new Account();
acc.Name =’Name’+i;
acc.Call_List_Frequency__c=8;
acc.Call_List__c=true;
acc.Call_List_Start_Date__c=system.today()-1;
acc.Call_List_Preferred_Day__c=’MOnday’;
date myDate = date.today();
acc.Call_List_Next_Preferred_Date__c=myDate.toStartofWeek()+0;
Account acc1 = new Account();
acc1.Name =’Name1’+i;
acc1.Call_List_Frequency__c=6.0;
acc1.Call_List__c=true;
acc1.Call_List_Start_Date__c=system.today()-1;
acc1.Call_List_Preferred_Day__c=’Tuesday’;
date myDate1 = date.today();
acc1.Call_List_Next_Preferred_Date__c=myDate1.toStartofWeek()+1;
lstAccount1.add(acc1);
Account acc2 = new Account();
acc2.Name =’Name1’+i;
acc2.Call_List_Frequency__c=6.0;
acc2.Call_List__c=true;
acc2.Call_List_Start_Date__c=system.today()+1;
acc2.Call_List_Preferred_Day__c=’Wednesday’;
date myDate2 = date.today();
acc2.Call_List_Next_Preferred_Date__c=myDate2.toStartofWeek()+2;
lstAccount2.add(acc2);
Account acc3 = new Account();
acc3.Name =’Name1’+i;
acc3.Call_List_Frequency__c=6.0;
acc3.Call_List__c=true;
acc3.Call_List_Start_Date__c=system.today()-1;
acc3.Call_List_Preferred_Day__c=’Thursday’;
date myDate3 = date.today();
acc3.Call_List_Next_Preferred_Date__c=myDate3.toStartofWeek()+3;
lstAccount3.add(acc3);
Account acc4 = new Account();
acc4.Name =’Name1’+i;
acc4.Call_List_Frequency__c=6.0;
acc4.Call_List__c=true;
acc4.Call_List_Start_Date__c=system.today()-1;
acc4.Call_List_Preferred_Day__c=’Friday’;
date myDate4 = date.today();
acc4.Call_List_Next_Preferred_Date__c=myDate4.toStartofWeek()+4;
lstAccount4.add(acc4);
Account acc5 = new Account();
acc5.Name =’Name1’+i;
acc5.Call_List_Frequency__c=6.0;
acc5.Call_List__c=true;
acc5.Call_List_Start_Date__c=system.today()-1;
acc5.Call_List_Preferred_Day__c=’None’;
acc5.Call_List_Next_Preferred_Date__c=system.today();
lstAccount5.add(acc5);
}
insert lstAccount;
insert lstAccount1;
insert lstAccount2;
insert lstAccount3;
insert lstAccount4;
insert lstAccount5;
Test.startTest();
UpdateAccountCallList obj = new UpdateAccountCallList();
obj.currentweek=9;
DataBase.executeBatch(obj);
Test.stopTest();
}
}
As I see, your class name would be 'UpdateAccountCallList' and the below code is the constructor method. so yoy have to pass the string type array to create the object. Try something like below, regards
I have tried your code as below.
insert lstAccount;
insert lstAccount1;
insert lstAccount2;
insert lstAccount3;
insert lstAccount4;
insert lstAccount5;
Test.startTest();
UpdateAccountCallList obj = new UpdateAccountCallList();
obj.currentweek=9;
DataBase.executeBatch(obj);
String [] arrOrg= new String[]{'org1','org2'};
UpdateAccountCallList objUpdateAccountCallList= new UpdateAccountCallList(arrOrg);
but i got same error on the line which i did bold.
Your code should be like below, regards
Same error: Error: Compile Error: Constructor not defined: [UpdateAccountCallList].<Constructor>(List<String>) at line 90 column 55.
Test.startTest();
String [] arrOrg= new String[]{'org1','org2'};
UpdateAccountCallList objUpdateAccountCallList= new UpdateAccountCallList(arrOrg);
objUpdateAccountCallList.currentweek=9;
DataBase.executeBatch(objUpdateAccountCallList);
Could you provide the batch class code with the existing construcor methods
UpdateAccountCallList obj = new UpdateAccountCallList(<PASSYOUR_ constructor >);
i passed like below. but it thowring an error.
String [] arrOrg= new String[]{'org1','org2'};
UpdateAccountCallList obj = new UpdateAccountCallList(UpdateAccountCallList objUpdateAccountCallList= new UpdateAccountCallList(arrOrg));
Below is my class
global class UpdateAccountCallList implements Database.Batchable<sObject>{
private list<String> sOrganization;
public UpdateAccountCallList(String[] sorg) {
sOrganization = sorg;
}
global Database.QueryLocator start(Database.BatchableContext BC)
{
return Database.getQueryLocator('SELECT Id,Organization__c FROM Account and Organization__c IN :sOrganization');
}
Change your execute method as
And test class
Here Organization__c ogr = new Organization__c () ; is not object its picklist field in the account.
"Error: Compile Error: Invalid type: Organization__c at line 22 column 5"
Below is my code can you guys help me out and i am passing this sorg data from scedhular class(SAP_0333,SAP_0975) are values.
global class UpdateAccountCallList implements Database.Batchable<sObject>{
private list<String> sOrganization;
public UpdateAccountCallList(String[] sorg) {
sOrganization = sorg;
}
//id rec='0014E00000lpSO7';
//string query = 'SELECT Id,Current_Week__c, Call_List__c,Call_List_Preferred_Day__c,Call_List_Start_Date__c,Call_List_Frequency__c,Call_List_Last_Updated_Date__c FROM Account where Call_List_Start_Date__c != null and Call_List__c=true and id=\'' + rec + '\'';
//system.debug('!!!!!'+ query);
global decimal currentweek;
global Database.QueryLocator start(Database.BatchableContext BC)
{
return Database.getQueryLocator('SELECT Id,Sales_Organization__c,Current_Week__c,Start_Week__c, Call_List__c,Call_List_Preferred_Day__c,Call_List_Start_Date__c,Call_List_Frequency__c,Call_List_Last_Updated_Date__c FROM Account where Call_List_Start_Date__c != null and Call_List_Frequency__c !=null and Sales_Organization__c IN :sOrganization');
}
global void execute(Database.BatchableContext BC,List<Account> scope) {
system.debug('execute method'+scope);
decimal week;
for(Account a : scope)
{
if(a.Call_List_Start_Date__c !=null && a.Call_List_Start_Date__c < date.today() && a.Call_List_Frequency__c !=null)
{
integer Evenweek=a.Current_Week__c.intvalue();
integer evenfrequency=a.Call_List_Frequency__c.intValue();
if( math.mod(evenfrequency, 2) == 0 && a.Current_Week__c != null && a.Call_List_Frequency__c !=null)
{
week=a.Current_Week__c;
system.debug('!!!!!week'+week);
decimal freuency= a.Call_List_Frequency__c;
system.debug('!!!!!freuency'+freuency);
decimal startweek=week-a.Start_Week__c;
system.debug('!!!!!startweek'+startweek);
currentweek=startweek/freuency;
system.debug('!!!!!currentweek'+currentweek);
String currentweeks = String.valueOf(currentweek);
System.debug('!!!!!!currentweeks '+currentweeks );
if(currentweeks.indexOf('.') == -1 )
//if(Math.mod(Integer.valueOf(startweek),Integer.valueOf(a.Call_List_Frequency__c)) == 0)
{
//system.debug('@@@'+Math.mod(Integer.valueOf(a.Current_Week__c),Integer.valueOf(a.Call_List_Frequency__c) ));
a.Call_List__c=true;
system.debug('!!!!!currentweek'+a.Call_List__c);
a.Call_List_Last_Updated_Date__c=system.today();
Integer dayCount=0;
if(a.Call_List_Preferred_Day__c=='Monday')
{
dayCount=0;
date myDate = date.today();
a.Call_List_Next_Preferred_Date__c = myDate.toStartofWeek().addDays(dayCount)+1;
}
else if(a.Call_List_Preferred_Day__c=='Tuesday')
{
dayCount=1;
date myDate = date.today();
a.Call_List_Next_Preferred_Date__c = myDate.toStartofWeek().addDays(dayCount)+1;
system.debug('@@@callist'+a.Call_List_Next_Preferred_Date__c);
}
else if(a.Call_List_Preferred_Day__c=='Wednesday')
{
dayCount=2;
date myDate = date.today();
a.Call_List_Next_Preferred_Date__c = myDate.toStartofWeek().addDays(dayCount)+1;
}
else if(a.Call_List_Preferred_Day__c=='Thursday')
{
dayCount=3;
date myDate = date.today();
a.Call_List_Next_Preferred_Date__c = myDate.toStartofWeek().addDays(dayCount)+1;
}
else if(a.Call_List_Preferred_Day__c=='Friday')
{
dayCount=4;
date myDate = date.today();
a.Call_List_Next_Preferred_Date__c = myDate.toStartofWeek().addDays(dayCount)+1;
}
else if(a.Call_List_Preferred_Day__c=='None')
{
a.Call_List_Next_Preferred_Date__c=system.today();
}
}
else
{
a.Call_List__c=false;
a.Call_List_Next_Preferred_Date__c= null;
a.Call_List_Last_Updated_Date__c=system.today();
}
}
else
{
decimal Eweek=a.Current_Week__c;
//system.debug('!!!!!Eweek'+Eweek);
decimal Efreuency= a.Call_List_Frequency__c;
system.debug('!!!!!Efreuency'+Efreuency);
decimal Estartweek=Eweek-a.Start_Week__c;
system.debug('!!!!!Estartweek'+Estartweek);
decimal Ecurrentweek=Estartweek/Efreuency;
system.debug('!!!!!Ecurrentweek'+Ecurrentweek);
String Ecurrentweeks = String.valueOf(Ecurrentweek);
System.debug('!!!!!!Ecurrentweeks'+Ecurrentweeks );
if(Ecurrentweeks.indexOf('.') == -1 )
{
a.Call_List__c=true;
system.debug('!!!!callist'+a.Call_List__c);
a.Call_List_Last_Updated_Date__c=system.today();
system.debug('!!!!calllast'+a.Call_List_Last_Updated_Date__c);
Integer dayCount=0;
if(a.Call_List_Preferred_Day__c=='Monday')
{
dayCount=0;
date myDate = date.today();
a.Call_List_Next_Preferred_Date__c = myDate.toStartofWeek().addDays(dayCount)+1;
system.debug('!!!!calllast'+a.Call_List_Next_Preferred_Date__c);
}
else if(a.Call_List_Preferred_Day__c=='Tuesday')
{
dayCount=1;
date myDate = date.today();
a.Call_List_Next_Preferred_Date__c = myDate.toStartofWeek().addDays(dayCount)+1;
system.debug('!!!!calllast'+a.Call_List_Next_Preferred_Date__c);
}
else if(a.Call_List_Preferred_Day__c=='Wednesday')
{
dayCount=2;
date myDate = date.today();
a.Call_List_Next_Preferred_Date__c = myDate.toStartofWeek().addDays(dayCount)+1;
system.debug('!!!!!callistpref'+a.Call_List_Next_Preferred_Date__c);
}
else if(a.Call_List_Preferred_Day__c=='Thursday')
{
dayCount=3;
date myDate = date.today();
a.Call_List_Next_Preferred_Date__c = myDate.toStartofWeek().addDays(dayCount)+1;
system.debug('!!!!calllast'+a.Call_List_Next_Preferred_Date__c);
}
else if(a.Call_List_Preferred_Day__c=='Friday')
{
dayCount=4;
date myDate = date.today();
a.Call_List_Next_Preferred_Date__c = myDate.toStartofWeek().addDays(dayCount)+1;
system.debug('!!!!calllast'+a.Call_List_Next_Preferred_Date__c);
}
else if(a.Call_List_Preferred_Day__c=='None')
{
a.Call_List_Next_Preferred_Date__c=system.today();
system.debug('!!!!calllast'+a.Call_List_Next_Preferred_Date__c);
}
}
else
{
a.Call_List__c=false;
a.Call_List_Next_Preferred_Date__c= null;
a.Call_List_Last_Updated_Date__c=system.today();
}
}
}
}
update scope;
}
global void finish(Database.BatchableContext BC)
{
}
}