2

I have an error popping up when I'm trying to call a method from another class. It's telling me the method doesn't exist or incorrect signature. Here's the breakdown of how it's working:

public with sharing class QuoteCalcUtil{
public String userEndDay;
public String userEndMonth;
public String userEndYear;

public void populateEndDates(String year, String month, String day)
   {
        userEndDay = day;
        userEndMonth = month;
        userEndYear = year;
    }
}

I have another class which is actually a controller which gets the values of userEndDay,userEndMonth,userEndYear from a visualforce page based on the user input. I want these values to then get passed to the QuoteCalcUtil class.

//This is the controller class

public with sharing class Checkbox_Class_V2
{
QuoteCalcUtil utility;
public String userEndDay {get; set;} //these three string variables are directly received from the visualforce page based on user input
public String userEndMonth {get; set;}
public String userEndYear {get; set;}

public PageReference getSelected()
  {
utility.populateEndDates(userEndDay,userEndMonth,userEndYear); //sending the user input values to the QuoteCalcUtil class using this method. 
/more code here
  }
}

The error occurs in the utility.populateEndDates line since it seems to be unhappy with the string parameters I'm giving it. Here is the exact error:

Save error: Method does not exist or incorrect signature: [QuoteCalcUtil].populateEndDates(String, String, String).

From what I can tell, I don't think i've done anything wrong. I've tried making the populateEndDates method a static method but that didn't solve it. I'm also instantiating the QuoteCalcUtil beforehand but again that isn't solving anything. From what I understand, those are the two ways to solve an error like this. Any ideas?

  • 2
    In your question the class name is QuoteCaclUtil rather than QuoteCalcUtil. Seems like a typo in Calc. – Daniel Ballinger Jul 10 '13 at 19:15
  • yup, just a typo when I was writing the code here on stackexchance. Fixed now. – SSadat Jul 10 '13 at 19:23
  • 1
    Does utility.populateEndDates('','',''); work? Removing a parameters from the equation will narrow down the possible cause of the error. Maybe try creating an instance of QuoteCalcUtil and calling the method in anonymous Apex. – Daniel Ballinger Jul 10 '13 at 19:30
  • I removed all the parameters of the populateEndDates and I'm still getting the same error which has narrowed down the error for me. It seems that the method itself does not exist. – SSadat Jul 10 '13 at 20:00
  • Seems like a few possible problems could exist. 1) There is a Typo in your code for the class name, 2) There is a typo in your code for the method name, 3) There was an error saving the QuoteCalcUtil class definition and the method doesn't exist in Salesforce, 4) There is a mismatch in calling a method that is or is not static. – Daniel Ballinger Jul 10 '13 at 20:20
1

Although you are declaring the variable utility as a type of QuoteCalcUtil, you're not actually instantiating it. Your text says you tried that and it didn't work; what did that code look like, and what error did you get in that case?

Try this line in the constructor of your Checkbox_Class_V2 class, or it should work within the setSelector() method as well:

utility = new QuoteCalcUtil();

Another option would be to change your existing declaration to declare the variable and instantiate it at the same time:

QuoteCalcUtil utility = new QuoteCalcUtil();
| improve this answer | |
0

I agree with @Daniel that when I get this error message it has to do with use as an instance method when declared as a static method, or vice-versa.

You can always try writing a new QuoteCalcUtil2 class, getting it to compile successfully, and then referring to it from the controller. Sometimes you get situations where class a references class B and vice-versa and SFDC won't let you resolve the dependencies because the other class always needs compiling but it too depends on your current class being edited successfully compiling.

Once you get around the compiler error, in class QuoteCalcUtil, method populateEndDates is an instance method. Your controller never does a this.utility = new QuoteCalcUtil();. Thus the statement utility.populateEndDates(userEndDay,userEndMonth,userEndYear); will have a null pointer exception

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.