Skip to main content The Trailblazer Community will be unavailable from 2/1/2025 to 2/2/2025. Please plan your activities accordingly.
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();

}

}
13 answers
  1. Nov 20, 2018, 5:03 AM
    when i added above code i am getting an error like below.

    "Error: Compile Error: Invalid type: Organization__c at line 22 column 5"
  2. Nov 20, 2018, 4:58 AM
    Hi Raj,

    Here Organization__c  ogr = new Organization__c () ; is not object its picklist field in the account.
  3. Nov 20, 2018, 4:46 AM
    Complete code

    Change your execute method as

     

    global Database.QueryLocator start(Database.BatchableContext BC)

    {

    return Database.getQueryLocator('SELECT Id,Organization__c FROM Account Where Organization__c IN :sOrganization');

    }

    And test class

    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>();

    Organization__c ogr = new Organization__c () ;

    ogr.Name ='Test' ;

    insert ogr ;

    Organization__c ogr1 = new Organization__c () ;

    ogr1.Name ='Test' ;

    insert ogr1 ;

    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.Organization__c = org.Id ;

    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.Organization__c = org1.Id ;

    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();

    String [] arrOrg= new String[]{'org1','org2'};

    UpdateAccountCallList obj = new UpdateAccountCallList(arrOrg);

    DataBase.executeBatch(obj);

    Test.stopTest();

    }

    }

     
  4. Nov 20, 2018, 4:43 AM
    Try like this

     

    String [] arrOrg= new String[]{'org1','org2'};

    UpdateAccountCallList obj = new UpdateAccountCallList(arrOrg);

     
  5. Nov 20, 2018, 4:43 AM
    Hi Raj,

    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');

        }
  6. Nov 20, 2018, 4:39 AM
    Hi Raj,

    i passed like below. but it thowring an error.

     String [] arrOrg= new String[]{'org1','org2'};

          UpdateAccountCallList obj = new UpdateAccountCallList(UpdateAccountCallList objUpdateAccountCallList= new UpdateAccountCallList(arrOrg)); 
  7. Nov 19, 2018, 2:27 PM
    Chane your code as below .. initialize your batch apex class with a constructor 

    UpdateAccountCallList obj = new UpdateAccountCallList(<PASSYOUR_ constructor >);

     

    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(<PASSYOUR_ CONSTRUCOT>);

    obj.currentweek=9;

    DataBase.executeBatch(obj);

    Test.stopTest();

    }

    }

     
  8. Nov 19, 2018, 9:07 AM
    Hi Sampath,

    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);
0/9000