You need to sign in to do that
Don't have an account?
Rst123
Error : Constructor not Defined : Btach class
I have a requirement where i have to get the all the object records (Entity_Name__c is a text field which contains object name in Policy_Type__c object ) and update those records in object Audit_Trail__c.
1> we need to query Policy_Type__c from which we will query all records of object(whichever is defined like account,contact etc) in Entity_Name__c
2> Condition__c is a text field where we define the condition on which SOQL will run .
3>After we get all records of object from Entity_Name__c we need to update these records in another object Audit_Trail__c
I'm getting Error : Constructor not Defined : Btach class when i'm trying to execute it in Developer console
Batch Class :-
global class POLICY implements Database.Batchable<sObject>, Database.Stateful{
Policy_Store__c myVariable = new Policy_Store__c();
String objectname = myVariable.Entity_Name__c;
String Condition = myVariable.Condition__c;
String query1;
String query2;
//Constructor
global POLICY(String query2){
query1 = 'Select Id, Name From '+objectname+' Limit 10000';
List<sObject> L = database.query(query1);
query2 = 'Select Id, Name,Policy_Type__c,Entity_Name__c,('+query1+') From Policy_Store__c where Policy_Type__c = "SOQL" and '+String.valueOf(Condition)+'';
List<sObject> L2 = database.query(query2);
}
// Start Method
global Database.QueryLocator start(Database.BatchableContext BC){
return Database.getQueryLocator(query2);
}
// Execute Mehod
global void execute(
Database.BatchableContext BC,
List<Policy_Store__c> scope){
//for(sObject s : scope){
//Summary = s.get('Policy_Store__c.Object_Name__c');
//}
Audit_Trail__c[] AudT = new List<Audit_Trail__c>();
for (Audit_Trail__c Au : AudT) {
Au.Entity_Name__c = myVariable.Entity_Name__c;
AudT.add(Au);
}
if(AudT.size()>0){
insert AudT;
}
}
global void finish(Database.BatchableContext BC){
}
}
1> we need to query Policy_Type__c from which we will query all records of object(whichever is defined like account,contact etc) in Entity_Name__c
2> Condition__c is a text field where we define the condition on which SOQL will run .
3>After we get all records of object from Entity_Name__c we need to update these records in another object Audit_Trail__c
I'm getting Error : Constructor not Defined : Btach class when i'm trying to execute it in Developer console
Batch Class :-
global class POLICY implements Database.Batchable<sObject>, Database.Stateful{
Policy_Store__c myVariable = new Policy_Store__c();
String objectname = myVariable.Entity_Name__c;
String Condition = myVariable.Condition__c;
String query1;
String query2;
//Constructor
global POLICY(String query2){
query1 = 'Select Id, Name From '+objectname+' Limit 10000';
List<sObject> L = database.query(query1);
query2 = 'Select Id, Name,Policy_Type__c,Entity_Name__c,('+query1+') From Policy_Store__c where Policy_Type__c = "SOQL" and '+String.valueOf(Condition)+'';
List<sObject> L2 = database.query(query2);
}
// Start Method
global Database.QueryLocator start(Database.BatchableContext BC){
return Database.getQueryLocator(query2);
}
// Execute Mehod
global void execute(
Database.BatchableContext BC,
List<Policy_Store__c> scope){
//for(sObject s : scope){
//Summary = s.get('Policy_Store__c.Object_Name__c');
//}
Audit_Trail__c[] AudT = new List<Audit_Trail__c>();
for (Audit_Trail__c Au : AudT) {
Au.Entity_Name__c = myVariable.Entity_Name__c;
AudT.add(Au);
}
if(AudT.size()>0){
insert AudT;
}
}
global void finish(Database.BatchableContext BC){
}
}
It seems like you are passing a string to constructor but it is not being used. So either remove it from there or call the batch from console as below :
POLICY pl= new POLICY('Some text');
Database.executeBatch(pl, 20);
Thanks,
AMit
I have tried executing the same way but still same pop-up error in developer console Constructor not defined: [POLICY].()
Can u please help where i'm doing wrong in batch class...
Thanks,
Amit
Database.executeBatch(pl, 20);
Hi RST1,
I hope 'xyz' is in single Quotes or it is declared as a string before executing the batch ?
Thanks,
Amit
Do u think there is any problem in code?
System.QueryException: unexpected token: 'null': Class.POLICY.: line 17, column 1 AnonymousBlock: line 1, column 1 AnonymousBlock: line 1, column 1