Id businessHoursId = [select Id from BusinessHours where isdefault = true ].id;
DateTime dateTime1 = Datetime.valueOf('2015-07-10 12:00:00');
DateTime dateTime2 = Datetime.valueOf('2015-07-13 12:00:00');
Long hours = Math.abs(BusinessHours.diff(businessHoursId,dateTime1,dateTime2)/1000/60/60);
Decimal days = hours / 24.0;
Above code gives 72 hours, but it should be 27 working hours. How can I modify this code to work as expected?
Best Answer
You most likely (from your comment) have not set up the business hours so they are all set to the default of 24 Hours a day 7 days a week.
A quick google search for "Salesforce set up business hours" yielded this gem:
https://help.salesforce.com/articleView?id=customize_supporthours.htm&type=0