You need to sign in to do that
Don't have an account?
Inputting date parameter into Apex test class
Hi All,
I'm attempting a Trailhead challenge and it requires me to create a test class on a method that takes date parameters. See below:
...this is my first test method:
"Method does not exist or incorrect signature: VerifyDate.CheckDates(Integer, Integer)"
Please help.
Thanks,
Mark
I'm attempting a Trailhead challenge and it requires me to create a test class on a method that takes date parameters. See below:
public class VerifyDate { //method to handle potential checks against two dates public static Date CheckDates(Date date1, Date date2) { //if date2 is within the next 30 days of date1, use date2. Otherwise use the end of the month if(DateWithin30Days(date1,date2)) { return date2; } else { return SetEndOfMonthDate(date1); } } //method to check if date2 is within the next 30 days of date1 private static Boolean DateWithin30Days(Date date1, Date date2) { //check for date2 being in the past if( date2 < date1) { return false; } //check that date2 is within (>=) 30 days of date1 Date date30Days = date1.addDays(30); //create a date 30 days away from date1 if( date2 >= date30Days ) { return false; } else { return true; } } //method to return the end of the month of a given date private static Date SetEndOfMonthDate(Date date1) { Integer totalDays = Date.daysInMonth(date1.year(), date1.month()); Date lastDay = Date.newInstance(date1.year(), date1.month(), totalDays); return lastDay; } }
...this is my first test method:
@istest private class TestVerifyDate { @istest static void method1crit1 (){ Date method1res1 = VerifyDate.CheckDates(12/15/15,12/16/15); system.assertEquals(12/16/15,method1res1); } }...and I am getting the following error in the problems tab of the Dev Console:
"Method does not exist or incorrect signature: VerifyDate.CheckDates(Integer, Integer)"
Please help.
Thanks,
Mark
All Answers
@ Mark Nemith,
The arguments data type of method CheckDates is date type but in your test class you are passing integer values.Please change the integer to date type as mentioned in below code snippet.
hope this make sense.
Thanks,
Karthick.S
Thanks for both of your answers. Clearly, they are both equally useful.
It helps to know that I can use both the parse() and newInstance() methods to pass date parameters.
Regards,
Mark