You need to sign in to do that
Don't have an account?

Calling a apex class method inside another class
Hi,
I was trying to call an method of class 1 in class 2. but i am getting this error while saving class 2.
Error: Compile Error: Constructor is not visible: <IPgap>(constructor)
Ex:
Class 1:
public class IPgap
{
public Opportunity opp{get; set;}
public IPgap (ApexPages.StandardController controller)
{
//Some logic
}
private void Info(){
intrest = new List<SelectOption>();
}
}
Class 2:
global without sharing class ipHelper {
//variable declarations
public void method1()
{
IPgap ipreq = new IPgap();
string returnValue = ipreq.Info();
}
}
Anyone can help me.
Thanks
Vivek
I was trying to call an method of class 1 in class 2. but i am getting this error while saving class 2.
Error: Compile Error: Constructor is not visible: <IPgap>(constructor)
Ex:
Class 1:
public class IPgap
{
public Opportunity opp{get; set;}
public IPgap (ApexPages.StandardController controller)
{
//Some logic
}
private void Info(){
intrest = new List<SelectOption>();
}
}
Class 2:
global without sharing class ipHelper {
//variable declarations
public void method1()
{
IPgap ipreq = new IPgap();
string returnValue = ipreq.Info();
}
}
Anyone can help me.
Thanks
Vivek
Thanks,
Alex
All Answers
It's becouse you try to call constructor without paramer, and this contructor not exists, you should pass ApexPages.StandardController to you IPgap contructor
Thanks,
Alex
Thanks,
Alex
The reason this is happening is because your constructor in class one is receiving a StandardController as a parameter. There are a few ways to resolve this, but that is up for you to decide. Here are the different ways I see to get around this.
- Create a new constructor in class 1 that doesnt take in any params.
- In Class two's method1, pass in a standard controller into your construct of class 1.
- Remove your overloaded constructor from class 1 and allow the built in constructor to be called.
Also it should be noted that your IPgap.info() method is private in scope and cannot be called from an outside class. You should either change the methods scope to be public or create another public method in class 1 that will call the info() mehtod.Hope that helps!