2

I have a client requirement where I want to send some notification emails only during weekdays and business hours.

I tried to Google this, and got to see that 'Business Hours' functionality must be implemented in Salesforce in order to achieve this. In my environment, PDT is the default Business Hours and it is active.

My question is, how can I set the email to fire only during the weekdays and during business hours? Is there a standard functionality available to do the same?

Google did not provide much of an answer to this.

Kindly help, as I am new to Salesforce.

Thanks !

1
  • Before sending email check the working hours or weekday; may be through trigger; – itzmukeshy7 Apr 18 '16 at 5:13
1

You need Apex to check if you are within Business Hours. There isn't a simple solution here, but the Apex piece of it will look something like:

public with sharing class BusinessHoursServices
{
    static BusinessHours default
    {
        get
        {
            if (default == null)
                default = [SELECT Id FROM BusinessHours WHERE IsDefault = true];
            return default;
        }
        private set;
    }

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

    public static  Datetime nextStartDate()
    {
        return nextStartDate(Datetime.now());
    }
    public static Datetime nextStartDate(Datetime input)
    {
        return BusinessHours.nextStartDate(default.Id, input);
    }
}

You'll have to play around with the above in a trigger and see how to fit it in with config. For example, have a checkbox that causes the email alert to fire. If you meet your criteria and you're within business hours, check the box. If you meet the criteria outside business hours, fill in a separate Datetime field. You can set up a wfr with a time based field update that checks the box when you hit that Datetime.

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.