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
Sampada ambikar 9Sampada ambikar 9 

How to check below method using anonymous window.

Hi Everyone,

I am using bekow class to calculate business days.but when I am calling the method from anonymous window getting below error.Please let me know what mistake i m making.Thanks in advance.I am new to sfdc.

Calling from anonymous -- B2C_BusinessDays_Calculator.IsWeekendDay(11-16-2018);

Error
Line: 1, Column: 29
Method does not exist or incorrect signature: void IsWeekendDay(Integer) from the type B2C_BusinessDays_Calculator



public class B2C_BusinessDays_Calculator {

    List<Case> cases = [select Id,B2C_Pending_SME_Dt__c from Case where status in ('Pending SME','Pending Customer')];
    Id caseId = cases[0].Id;
    Date SMEDate = cases[0].B2C_Pending_SME_Dt__c;
    
    public static Boolean IsWeekendDay(Date SMEDate)
   {
      boolean result     = false;
      system.debug('SMEDate = '+SMEDate); 
      //Recover the day of the week
      Date startOfWeek   = SMEDate.toStartOfWeek();
      system.debug('startOfWeek = '+startOfWeek);
      Integer dayOfWeek  = SMEDate.day() - startOfWeek.day();
      system.debug('dayOfWeek = '+dayOfWeek);   
      result = dayOfWeek == 0 || dayOfWeek == 6 ? true : false;
      system.debug('result = '+result); 
      return result;
   } 
   
   
   public static Date AddBusinessDays(Date SMEDate, integer BusinessDaysToAdd )
   {
      //Add or decrease in BusinessDaysToAdd days 
      Date finalDate = SMEDate;
      system.debug('finaldate = '+finalDate);
      integer direction = BusinessDaysToAdd < 0 ? -1 : 1;
      system.debug('direction = '+direction);
       while(BusinessDaysToAdd != 0)
       {
           finalDate = finalDate.AddDays(direction);
           system.debug('BusinessDaysToAdd = '+BusinessDaysToAdd);            
           system.debug('finaldate = '+finalDate);
           if (!isWeekendDay(finalDate))
           {
               BusinessDaysToAdd -= direction;
               
           }
       }

       return finalDate;
   }
}

 
Best Answer chosen by Sampada ambikar 9
Raj VakatiRaj Vakati
Try like this  .. exceute the below code from  anonymous window.
 
B2C_BusinessDays_Calculator.IsWeekendDay(Date.newinstance(2018, 11, 16));

 

All Answers

Raj VakatiRaj Vakati
Try like this  .. exceute the below code from  anonymous window.
 
B2C_BusinessDays_Calculator.IsWeekendDay(Date.newinstance(2018, 11, 16));

 
This was selected as the best answer
Sampada ambikar 9Sampada ambikar 9
Thanks so much Raj...It's working fine