0

I have requirement, where i need to check the day is workingday or holiday for that i got one class but problem here is that, i have written trigger handler from handler class how can i pass date and holiday list to below class can anyone help me and also i am getting error while calling this method like this "boolean holidycheck= holidaylist.changeWeekendTaskDueDate(evetstartdate ,holidays);"

  public boolean checkifItisWorkingDay(Date currentDate,List<Holiday> holidays)
{
                 Date weekStart  = currentDate.toStartofWeek();
                for(Holiday hDay:holidays)
                {
                        if(currentDate.daysBetween(hDay.ActivityDate) == 0)
                        {
                                 return false;
                        }
                }
               if(weekStart.daysBetween(currentDate) ==0 || weekStart.daysBetween(currentDate) == 6)
               {
                   return false;
                } else

               return true;

Below is my trigger handler class

List<Holiday> holidays=[Select h.StartTimeInMinutes, h.Name, h.ActivityDate From Holiday h];

        List<contact> conts  = (List<contact>) newSobjs;// 

        List<Event> events = new List<Event>();

        for (contact ri : conts )

        {

            Event evt = new Event(whatID = ri.ID);
            evt.Subject = 'Bid Due Date for ' + ri.name;  
            Date evetstartdate = ri.Completion_Date__c;
            boolean holidycheck= holidaylist.changeWeekendTaskDueDate(evetstartdate ,holidays);    
            evt.StartDateTime = evetstartdate;
            evt.DurationInMinutes= 30;  
            events.add(evt);

        }

        insert events;
3
  • Hmm, must you pass holidays like that? Asking because there is a GUI setup in Salesforce to define BusinessHours and Holidays and you can reference them in code. See developer.salesforce.com/docs/atlas.en-us.apexcode.meta/… help.salesforce.com/… help.salesforce.com/… Commented Apr 27, 2020 at 17:57
  • i got it thanks Commented Apr 28, 2020 at 10:32
  • public static Boolean IsWeekendDay(Date dateParam) { boolean result = false; system.debug('dateParam = '+dateParam); //Recover the day of the week Date startOfWeek = dateParam.toStartOfWeek(); system.debug('startOfWeek = '+startOfWeek); Integer dayOfWeek = dateParam.day() - startOfWeek.day(); system.debug('dayOfWeek = '+dayOfWeek); result = dayOfWeek == 0 || dayOfWeek == 6 ? true : false; system.debug('result = '+result); return result; } along with holiday method it got sovled Commented Apr 28, 2020 at 10:33

1 Answer 1

1

There is a GUI setup in Salesforce for admins to define BusinessHours and Holidays and these configurations can be used in coded solutions. See https://help.salesforce.com/articleView?id=customizesupport_holidays.htm&type=5

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .