Salesforce | Send an email alert to Lead owner after X business hours from Lead Creation timestamp

Author - Shalini

Let’s say our business hours are from 9am to 6pm (Monday to Friday) and if Lead is created at 5pm on Monday an email alert should be sent to LeadOwner at 12am on Tuesday.

You can set your business hours in Salesforce under Company Profile.
Above requirement can be achieved by using BusinessHours function in apex.
BusinessHours.add(businessHoursId, startDate, intervalMilliseconds)
Code snippet:

Datetime currentTime =;

Id businessHourId = [SELECT Id FROM BusinessHours WHERE IsDefault = true].id;

Integer hours =4 ;
Datetime emailSendDate = BusinessHours.add(businessHourId, currentTime, hours* 60 * 60 * 1000L);

Webner Solutions is a Software Development company focused on developing Insurance Agency Management Systems, Learning Management Systems and Salesforce apps. Contact us at for your Insurance, eLearning and Salesforce applications.

Leave a Reply

Your email address will not be published.