-2

I am testing the scheduled batch class in salesforce, during which i am getting the below error :

" Error: Compile Error: Constructor not defined: [LicenseOptimizer_BatchClass].(String) at line 19 column 48 "

I have searched the error in couple of sites and tried couple of suggested workarounds yet the error was solved. Any light on this is of great help .

complete test class : The test class below is merged code for all the dml operations in my application including the scheduled batch class. so i am only posting the batch class related test class.

Test class code :

public static testMethod void testLicenseBatchClass() {
        set<id> stUserId= new set<id>();

        list<Shift_Master__c > lstShift = new list<Shift_Master__c >();
        Shift_Master__c objShift;

        Custom_Comp_Info__c objCustomLicenseInfi = new Custom_Comp_Info__c(User_Licenses__c = 'Salesforce', Salesforce_Used_Licenses__c = 20, Salesforce_Total_Licenses__c =100);
        insert objCustomLicenseInfi ;

        datetime   CurrentDateTime = Datetime.now();
        string CurrentTime = CurrentDateTime.format('hh:mm:ss','IST');

        datetime      newDateTime1 = CurrentDateTime.addMinutes(-2);


        datetime       newDateTime2 = CurrentDateTime.addMinutes(8);


        String strEndDate = string.valueof(newDateTime1);
        String[] strCurrentTimeLessTen = strEndDate.split(' ');

        String strStartDate = string.valueof(newDateTime2);
        String[] strCCurrentTimeGreatTen  = strStartDate.split(' ');



        string strEndtime = strCurrentTimeLessTen[1] ;
        string strStarttime = strCCurrentTimeGreatTen[1] ;


        objShift = new Shift_Master__c( Shift__c = 'Regular', End_Time__c = '00:00:00' ,  Start_Time__c = strStarttime );
        lstShift.add(objshift);

        objShift = new Shift_Master__c( Shift__c = 'Afternoon', End_Time__c = strEndtime ,  Start_Time__c = '20:00:00');
        lstShift.add(objshift);


        objShift = new Shift_Master__c( Shift__c = 'Night', End_Time__c = '11:47:00',  Start_Time__c = '20:00:00');
        lstShift.add(objshift);



        insert lstShift;      

        Profile objProfile = [SELECT Id FROM Profile WHERE Name='Standard User'];

       User objUser = new User(Alias = 'standt', Email='[email protected]', 
                                EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', 
                                LocaleSidKey='en_US', ProfileId = objProfile.Id, Shift_Association__c ='Afternoon' ,
                                TimeZoneSidKey='America/Los_Angeles', UserName='[email protected]');

        User objUser1 = new User(Alias = 'standt1', Email='[email protected]', 
                                 EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', 
                                 LocaleSidKey='en_US', ProfileId = objProfile.Id, Shift_Association__c ='Regular' ,
                                 TimeZoneSidKey='America/Los_Angeles', UserName='[email protected]');


        insert objUser;

        User objUser11 = new User(Alias = 'standt11', Email='[email protected]', 
                                  EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', 
                                  LocaleSidKey='en_US', ProfileId = objProfile.Id, Shift_Association__c ='Night' ,
                                  TimeZoneSidKey='America/Los_Angeles', UserName='[email protected]');


        insert objUser11;

        insert objUser1;


       LicenseOptimizer_Automated objLicenseOptimizer_Automated = new LicenseOptimizer_Automated();
       objLicenseOptimizer_Automated.LicenseOptimizer();

        LicenseOptimizer_HelperClass objLicenseOptimizerHelperClass = new LicenseOptimizer_HelperClass();
        objLicenseOptimizerHelperClass.assigncontactQueue();


        Shift_Master__c objShift1 =[select Shift__c,End_Time__c , start_time__c from Shift_Master__c where Shift__c=:'Night'];
        objShift1.start_time__c = '11:11:11';
        objShift1.end_time__c ='12:12:12';

        update objShift1 ;


    }

Class which calls the batch class and realted helper class :

public with sharing class LicenseOptimizer_Automated
{



    public LicenseOptimizer_Automated ()
    {

    }
    public void LicenseOptimizer()
    {
    string strQuery = 'Select id, End_Time__c, user__c from  users__c';
    Id batchInstanceId = Database.executeBatch(new LicenseOptimizer_BatchClass(strQuery), 150);
    }

}

And finally the batch class execution class

global class LicenseOptimizer_BatchClass implements Database.Batchable<sObject>, Database.AllowsCallouts, Database.Stateful, Schedulable{

    global final String StrQuery;

    set<id> setUserId = new set<id>();


     global LicenseOptimizer_BatchClass()
    {
        StrQuery = 'Select id, End_Time__c, user__c from  users__c';
    }


    global void execute(SchedulableContext sc) {


      LicenseOptimizer_BatchClass pa= new LicenseOptimizer_BatchClass();
    string cronStr = '0 5 * * * ?';
    System.schedule('Process Accs Job', cronStr, pa);
      database.executebatch(pa);
  }

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




    global void execute(Database.BatchableContext BC, List<sObject> lstSobject){

    LicenseOptimizer_HelperClass objHelper = new LicenseOptimizer_HelperClass();

        for(Sobject objSobject : lstSobject)
        {
            setUserId.add(objSobject.id);
        }
if(!test.isRunningTest())
        objHelper.CheckTime(setUserId);
    }
    global void finish(Database.BatchableContext BC){
    }
}

1 Answer 1

0

When you execute batch you use:

new LicenseOptimizer_BatchClass(strQuery). 

But in code you have only constructor with no paramters. You have to add parameter in constructor or remove from 'new LicenseOptimizer_BatchClass(strQuery)'.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .