function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sfdc dev 2264sfdc dev 2264 

Constructor not defined: in schedulable class

Hi,

I am hyaving a scheduler class for my batch class which i am getting the following error

Error: Compile Error: Constructor not defined: [ContractBatchTriggerHandler].<Constructor>() at line 5 column 43
 
MY SCHEDULER CLASS :

global class ContractBatchTriggerHandler_Schedular implements Schedulable {

        global void execute(SchedulableContext sc) {

        ContractBatchTriggerHandler opb = new ContractBatchTriggerHandler();
        Database.executeBatch(opb,100);
        }
}
 
MY BATCH CLASS :

global class ContractBatchTriggerHandler implements Database.Batchable<sObject> {
Set<Id> contractIdSet = new Set<Id>();

    // Constructor will take set of new Contract IDs
    global ContractBatchTriggerHandler (Set<Id> contractIdSet){
        this.contractIdSet = contractIdSet;
    }
 global Database.QueryLocator start(Database.BatchableContext bc) {
        // Query all Contract records that were in Trigger.new
        return Database.getQueryLocator([SELECT Status__c, Account__c FROM Contract__c WHERE Id IN :contractIdSet]);
    }

    // The execute method will call three methods
    global void execute(Database.BatchableContext bc, List<Contract__c> scope) {
        ContractfieldsupdateonAccount(scope);
        contractcommencementdate(scope);
        contractexpirydate(scope);
    }

help me what i am doing wrong here

thanks
Best Answer chosen by sfdc dev 2264
Anurag SaxenaAnurag Saxena
global class ContractBatchTriggerHandler_Schedular implements Schedulable {
list<contract>Con = new list<contract>();
        global void execute(SchedulableContext sc) {
        Set<id> contractId = new Set<id>();
  for(Contract c :Con )
{
contractId.add(Con.id);
}
        ContractBatchTriggerHandler opb = new ContractBatchTriggerHandler(contractId);
        Database.executeBatch(opb,100);
        }
}

 

All Answers

Shweta_AgarwalShweta_Agarwal
Hi,
You need to pass set of contarct id in Constructor , becuse in your code you have wrriten  Constructor  with parameter .
Add folllowing line in your sheduler calss
Set<id> conractId = new Set<id>();
//add your logic to add contract id in set

ContractBatchTriggerHandler opb = new ContractBatchTriggerHandler(conractId );
Database.executeBatch(opb,100);

Thanks
sfdc dev 2264sfdc dev 2264
I have modified my scheduler class , let me know if its right

global class ContractBatchTriggerHandler_Schedular implements Schedulable {

        global void execute(SchedulableContext sc) {
        Set<id> contractId = new Set<id>();
        ContractBatchTriggerHandler opb = new ContractBatchTriggerHandler(contractId);
        Database.executeBatch(opb,100);
        }
}


or do i have to add the query in set<id> contract id ?

let me know

thanks
Anurag SaxenaAnurag Saxena
There is a spelling mistake in above 

please correct it
Set<id> conractId = new Set<id>();
//add your logic to add contract id in set

ContractBatchTriggerHandler opb = new ContractBatchTriggerHandler(contractId );
Database.executeBatch(opb,100);

Thanks
sfdc dev 2264sfdc dev 2264
I have modified my scheduler class , let me know if its right

global class ContractBatchTriggerHandler_Schedular implements Schedulable {

        global void execute(SchedulableContext sc) {
        Set<id> contractId = new Set<id>();
        ContractBatchTriggerHandler opb = new ContractBatchTriggerHandler(contractId);
        Database.executeBatch(opb,100);
        }
}


or do i have to add the query in set<id> contract id ?

let me know

thanks
Shweta_AgarwalShweta_Agarwal
Now it will not give error but your code will not execute becuse you are not passing contract id. So you need to add Id of contract in Set (
"contractId"
sfdc dev 2264sfdc dev 2264
where should i add id of contarct is it in batch class or scheduler class

let me know how to add it pls


thanks
Anurag SaxenaAnurag Saxena
global class ContractBatchTriggerHandler_Schedular implements Schedulable {
list<contract>Con = new list<contract>();
        global void execute(SchedulableContext sc) {
        Set<id> contractId = new Set<id>();
  for(Contract c :Con )
{
contractId.add(Con.id);
}
        ContractBatchTriggerHandler opb = new ContractBatchTriggerHandler(contractId);
        Database.executeBatch(opb,100);
        }
}

 
This was selected as the best answer
sfdc dev 2264sfdc dev 2264
I am getting the below error

Error: Compile Error: Initial term of field expression must be a concrete SObject: List<Contract__c> at line 7 column 16

global class ContractBatchTriggerHandler_Schedular implements Schedulable {
list<Contract__c>Con = new list<Contract__c>();
        global void execute(SchedulableContext sc) {
        Set<id> contractId = new Set<id>();
  for(Contract__c c :Con )
{
contractId.add(Con.id);
}
        ContractBatchTriggerHandler opb = new ContractBatchTriggerHandler(contractId);
        Database.executeBatch(opb,100);
        }
}
Anurag SaxenaAnurag Saxena
try this code 

let me know what happens?

 
Shweta_AgarwalShweta_Agarwal
for(Contract__c c :Con )
{
contractId.add(c.id);
}

 
sfdc dev 2264sfdc dev 2264
thanks anurag and swetha , it worked
Anurag SaxenaAnurag Saxena
global class ContractBatchTriggerHandler_Schedular implements Schedulable {
list<Contract__c>Con = new list<Contract__c>();
        global void execute(SchedulableContext sc) {
        Set<id> contractId = new Set<id>();
  for(Contract__c c :Con )
{
contractId.add(c.id);
}
        ContractBatchTriggerHandler opb = new ContractBatchTriggerHandler(contractId);
        Database.executeBatch(opb,100);
        }
}

try this