• BOUGUEM SIHOUTE Joelle
  • NEWBIE
  • 0 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hi Guys,

As a part of learning salesforce i got some errors in testClass. Need help on those errors. why they got ?

Error: Compile Error: Method is not visible: VerifyDate.DateWithin30Days(Date, Date) at line 31 column 21, and
Error: Compile Error: Method does not exist or incorrect signature: VerifyDate.SetEndOfonMonthDate(Date) at line 40 column 21

Apex Class:
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;
    }

}

and below is my testClass:
@isTest

private class TestVerifyDate{

    @isTest static void TVD1(){
    
        Date Date1 = Date.parse('1/03/16');
        Date Date2 = Date.parse('12/03/16');

        Date TVD1 = VerifyDate.CheckDates(Date1, Date2);
        System.assertEquals(Date2, TVD1);

    }
    
    @isTest static void TVD2(){
    
        Date Date1 = Date.parse('1/03/16');
        Date Date2 = Date.parse('12/03/16');
        Date firstDayOfMonth = System.today().toStartOfMonth();

        Date TVD2 = VerifyDate.CheckDates(Date1,Date2);
        System.assertEquals(Date1.addDays(Date.daysInMonth(firstDayOfMonth.year(), firstDayOfMonth.month()) - 1), TVD2);

    }
    
    @isTest static void TVD3(){
    
      	Date Date1 = Date.parse('1/03/16');
       	Date Date2 = Date.parse('12/03/16');
        
       	Date TVD3 = VerifyDate.DateWithin30Days(Date1, Date2);
       	System.assertEquals(false, TVD3);

   }
    
   @isTest static void TVDL(){
    
       	Date Date1 = Date.parse('1/03/16');
       
        Date TVDL = VerifyDate.SetEndOfonMonthDate(Date1);
        System.assertEquals(Date1, TVDL);

   }


}

any modifications to the testClass ? Help me regarding this.
 
  • March 18, 2016
  • Like
  • 0