1

I have a requirement where I need to send email in 8 business hours. It should respect holidays and weekends.

Example: Office Hours 8 AM to 5 PM

If case is created at 4 PM Friday then email must be sent to 3 PM on Monday as Saturday Sunday are non working days.

Should I write trigger and Schedule action or Create field and update value and use WF rule. Sample code will be helpful.

Thanks in Advanced!

1 Answer 1

3

You could write a Case Trigger and call a trigger handler. Add this following method to return DateTime respecting business hours.

public static DateTime SLADateTime(Datetime input, Long intervalMilliseconds)
    {
         BusinessHours defaultBH = [SELECT Id FROM BusinessHours WHERE IsDefault = true];
         return BusinessHours.add(defaultBH.Id, input, intervalMilliseconds);
    }

You need to pass the creation datetime and 8*60*60*1000 as duration, considering 8 hours is the duration.

Create a new datetime field and store the above returned value in that field.

Finally create a scheduled action through workflow or process builder based on this datetime and send an email.

3
  • 1
    Hi Santanu, Thanks for your response . This is really helpful. Commented Sep 17, 2018 at 7:09
  • Hi Santanu, Will it follow Current user time zone? I set Business Hours as 8 AM to 5 PM EST. Commented Sep 18, 2018 at 13:58
  • It will follow any timezone which has been defined in business hours configuration. Commented Sep 18, 2018 at 16:34

You must log in to answer this question.

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