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
Nikhil M KumarNikhil M Kumar 

How can I use the Constructor of a Wrapper outside it (in the Main Class) ?

I have defined a Wrapper class inside a Main class.
When I try to use the Constructor of the Wrappe class outside the Wrapper class (except in Main Class Constructor), an error shows up as below:
Constructor not defined: [JSONParserUtil.JSONParserUtilWrapper].<Constructor>()
What can I do, so as to use the Wrapper class's Constructor in other methods of the Main class?
 
Best Answer chosen by Nikhil M Kumar
Nikhil M KumarNikhil M Kumar
Hey!
I just got it solved.. The problem is that the Constructor should be defined just like it was defined inside the Wrapper class (with the same type and number of parameters).
For example, if you have defined it initially as:
WrapperConstructor(String s, Integer i){
    //Constructor Body..
}

Then, you should use it the same way unless you have defined another constructor with different type and number of parameters or no parameters (depending on your requierement), which is also popularly called as "Overloading"!!

And, Thank you Devi, for seeking out to help!

All Answers

Devi ChandrikaDevi Chandrika (Salesforce Developers) 
Hi Nikhil,
can you post your code here
Nikhil M KumarNikhil M Kumar
Hey!
I just got it solved.. The problem is that the Constructor should be defined just like it was defined inside the Wrapper class (with the same type and number of parameters).
For example, if you have defined it initially as:
WrapperConstructor(String s, Integer i){
    //Constructor Body..
}

Then, you should use it the same way unless you have defined another constructor with different type and number of parameters or no parameters (depending on your requierement), which is also popularly called as "Overloading"!!

And, Thank you Devi, for seeking out to help!
This was selected as the best answer