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

Author - Shalini
19.06.2017
|
0 Comments
|

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.
1
Above requirement can be achieved by using BusinessHours function in apex.
BusinessHours.add(businessHoursId, startDate, intervalMilliseconds)
Code snippet:

Datetime currentTime = System.now();

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 dev@webners.com for your Insurance, eLearning and Salesforce applications.

Leave a Reply

Your email address will not be published. Required fields are marked *