You need to sign in to do that
Don't have an account?
Error: Unknown constructor
I have been trying to get rid of this error and tried all posible things, but still I cant understand why I am getting this error-
Error- Error: Unknown constructor 'mappingRules1.mappingRules1()- This error I am getting when I try to save the VF page
Requirement is- To invoke a batch class through a custom button
I have created 3 things-
1) Controller Class
2) Batch Class which linked to the Controller class
3) Visualforce page
Details-
Batch Class:
global class BatchMappingRules implements Database.Batchable<sObject>{
global integer jobid;
Public Boolean runTestMethod = false;
public BatchMappingRules(integer jobid){
this.jobid=jobid;
}
global Database.queryLocator start(Database.BatchableContext ctx){
if(runTestMethod){
return Database.getQueryLocator(mappingRules1.select_batch_scope(jobid)+' '+'Limit 100');
}
return Database.getQueryLocator(mappingRules1.select_batch_scope(jobid));
}
global void execute(Database.BatchableContext ctx, List<Sobject> scope){
BatchStatic.setAlreadyUpdated();
List<Id> list01 = new List<Id>();
for(SObject rec : scope) {
list01.add(rec.id);
}
boolean result = mappingRules1.startUp(list01);
}
global void finish(Database.BatchableContext ctx){
}
}
Controller Class:
global class mappingRules1{
Public Siebel_to_Salesforce_ObjectMap__c cListObject = new Siebel_to_Salesforce_ObjectMap__c();
Public Siebel_to_Salesforce_FieldMap__c cListField = new Siebel_to_Salesforce_FieldMap__c();
global static String select_batch_scope(integer jobid) {
String query = '[Select id from Siebel_to_Salesforce_FieldMap__c] UNION [Select id from Siebel_to_Salesforce_ObjectMap__c]';
System.Debug('>>>>>>>>>>>>>query text :: '+query );
return query;
}
List<Id> listId=new List<Id>();
public mappingRules1(List<Id> listId) {
this.listId= listId;
}
public List<Siebel_to_Salesforce_FieldMap__c> cField (Id[] listId){
return [SELECT Id,SIEBEL_TABLE_NAME__c,SIEBEL_COLUMN_DATA__c,SALESFORCE_OBJECT_NAME__c,SFDC_COLUMN_NAME__c,SDFC_DATA_TYPE__c,SFDC_LENGTH__c,SIEBEL_COLUMN_NAME__c,SIEBEL_COLUMN_LENGTH__c,SFDC_EXTERNAL_ID__c, Object_Mapping_Id__c FROM Siebel_to_Salesforce_FieldMap__c WHERE Id IN : listId];
}
public List<Siebel_to_Salesforce_ObjectMap__c> cObject(Id[] listId){
return [SELECT Id, Label__c, Salesforce_Object_Name__c, allow_reports__c, allow_activities__c, track_field_history__c, deployment_status__c,SIEBEL_TABLE_NAME__c,Serial_Number__c FROM Siebel_to_Salesforce_ObjectMap__c WHERE Id IN : listId];
}
public void checkObject(){
List <Siebel_to_Salesforce_ObjectMap__c> cListObject = new List <Siebel_to_Salesforce_ObjectMap__c>();
cListObject=cObject(listId);
for(Siebel_to_Salesforce_ObjectMap__c obj: cListObject){
if(obj.Label__c == NULL){
obj.Label__c=obj.Salesforce_Object_Name__c;
}
//Some Business Rules
}
update (cListObject);
}
public void checkField(){
String col;
List <Siebel_to_Salesforce_ObjectMap__c> obList = new List <Siebel_to_Salesforce_ObjectMap__c>();
List <Siebel_to_Salesforce_FieldMap__c> cListField = new List <Siebel_to_Salesforce_FieldMap__c>();
cListField=cField(listId);
obList=cobject(listId);
Map<String, Siebel_to_Salesforce_ObjectMap__c> mapp= new Map<String, Siebel_to_Salesforce_ObjectMap__c>();
for(Siebel_to_Salesforce_ObjectMap__c r:obList){
mapp.put(r.Serial_Number__c,r);
}
for(Siebel_to_Salesforce_FieldMap__c field: cListField){
//Some Business Rules
}
update(cListField);
}
webservice static Boolean startUp(List<Id> listId){
integer resultCounter = 0;
mappingRules1 rules= new mappingRules1(listId);
rules.checkObject();
rules.checkField();
return true;
}
}
VF Page:
<apex:page sidebar="false" Controller="mappingRules1">
<apex:form >
<apex:commandButton value="Process" action="{!startUp}">
</apex:commandButton>
</apex:form>
</apex:page>
Thanks in Advance
Hi subbu,
You have passed parameter in your constructor (List<Id> listId) which is not support visualforce page. Instead of that you have to declate constructor without any parameters as below.
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator
My Blog:- http://mrjavascript.blogspot.in/
Hi Hitesh,
I did the modifications as suggested by you, but I am getting another error. The error is-
Error: Compile Error: cannot reference instance variables or instance methods inside a constructor invocation. This error i am getting for this line - ""this(listId);""
Hi,
Take one static variable and use that variable instead listId.
Example:
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator
My Blog:- http://mrjavascript.blogspot.in/
Great. But I got one more pop up error.-
Error: Unknown method 'mappingRules1.startUp()' Create Apex method 'mappingRules1.startUp'.
But this method is already present.
Hi,
You have to pass parameter in mappingRules1.startUp() method like below.
List<Id> lstId = new List<Id>();
mappingRules1.startUp(lstId);
Hi Hitesh,
Yes I have already passed a parameter to the startUp() method, but it is throwing an error that the method startUp() doesnt exist. I am using "action" for invoking the startUp method through the visualforce page-
<apex:commandButton value="Process" action="{!startUp}">
It is searching for a method startUp(), but it is not able to find it. The method startUp() involves some arguments, but how to invoke a method through VF, which has some arguments passed, arguments are passed not through VF by another class.So how to invoke such parameterised method using VF.