1

I have a requirement where I have to update a field on the case and send an email 15mins after (according to working hours) case has been created/modified to status = Open. Can this achieved without writing any sort of code or may be less code ?

  • 1
    It really has to be working hours? That significantly complicates the picture. – Adrian Larson May 9 '17 at 17:46
  • 2
    How about just using standard Escalations? You can't "set a field", but it adds a nice big red arrow next to the case number and can send an email. – sfdcfox May 9 '17 at 17:47
  • The working hours is the thing which has to be taken care of,moreover i need to set a field with sending an email. – Raju Sen May 9 '17 at 17:55
  • I am keeping scheduled batch class as my last resort – Raju Sen May 9 '17 at 18:01
  • Thanks for your wonderful comments @SantanuBoral ,my purpose of asking was not solved ,so as you may see members do invest there time for people like us to help us out ,but at any point of time did you think I have denied that. – Raju Sen May 9 '17 at 18:40
1

This can be achieved by Time based workflow.

Also, time based workflow action fires on week days and it excludes weekends.

Time based workflow takes minimum 1 hour (before/after) based on specified date.

Here it is the trick!

Create a date time field and update that date time field from workflow field update using the formula = NOW()-0.03109 which will return 15 minutes.

Now, create a time dependent action to send a email and specify time trigger as

1 hour after that datatime field (NOW()-0.03109), so eventually it will fire after 15 mins.

Update

If you have a specific requirement on firing on Business hours then follow this approach.

Create a datetime field which can be updated from code.

Class

public with sharing class BusinessHoursServices
{
    //retrieves & assign the Organization level Business Hours to defaultBH 
    static BusinessHours defaultBH
    {
        get
        {
            if (defaultBH == null)
                defaultBH = [SELECT Id FROM BusinessHours WHERE IsDefault = true];
            return defaultBH;
        }
        private set;
    }

    public static Boolean isWithin()
    {
        return isWithin(Datetime.now());
    }
    public static Boolean isWithin(Datetime input)
    {
        return BusinessHours.isWithin(defaultBH.Id, input);
    }


    /**
    * getSLATimeByBusinessHourGmt
    * converts the given dateTime into Gmt Format with Respect to Business Hours & SLA's. 
    * @param input - DateTime Field to Convert into Gmt.
    * @param SLAhours - Integer value to add SLA Hours.   
    * @return Datetime
    */
    public static Datetime getSLATimeByBusinessHourGmt (DateTime input, Integer SLAhours)
    {
        return BusinessHours.addGmt(defaultBH.Id,input, SLAhours* 60 * 60 * 1000L);
    }

   /**
    * getSLATimeByBusinessHour
    * converts the given dateTime into Local Format with Respect to Business Hours & SLA's. 
    * @param input - DateTime Field to Convert into Gmt.
    * @param SLAhours - Integer value to add SLA Hours.   
    * @return Datetime
    */
    public static Datetime getSLATimeByBusinessHour (DateTime input, Integer SLAhours)
    {
        return BusinessHours.add(defaultBH.Id,input, SLAhours* 60 * 60 * 1000L);
    }

}

Calculate and update datetime

Datetime currentTime = System.now();
System.debug('current time=' + System.now());
TimeZone tz = UserInfo.getTimeZone();
System.debug('Display name: ' + tz.getDisplayName());

System.debug('Current local time=' + currentTime.format('MM-dd-yyyy ') + ' ' + currentTime.format('h:mm a'));

//check the current datetime falling on the same business day
Boolean isSameDayWithinBusinessHour =  BusinessHoursServices.isWithin(System.now());
System.debug('isSameDayWithinBusinessHour=' + isSameDayWithinBusinessHour);

Datetime targetDT = BusinessHoursServices.getSLATimeByBusinessHour.add(currentTime, 1.25);

And in the time based workflow specify 1 hour before this targetDT, so it will eventually fire after 15 minutes recognizing business hours.

  • I have one question will IsWithin method will check whether it is saturday or sunday i.e. will it exclude Holidays and weekends? – Raju Sen May 10 '17 at 11:12
  • It will check if it is within business hours that has been configured in your system – Santanu Boral May 10 '17 at 12:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.