I have the three field like below and I want to calculate the business hours but need to reduce the hour if the exist the holiday.
I have write this code into the apex class and call this class form the trigger after update.
BusinessHours bh = [SELECT id From BusinessHours
Where IsDefault=true];
Datetime inTime = custom date time field 1
Datetime outTime = Custom date time field 2;
long businessMillisecondsDiff = BusinessHours.diff(bh.Id, inTime, outTime);
decimal businessHoursDiff = businessMillisecondsDiff / (1000.0*60.0*60.0);
custom_text_field__c = businessHoursDiff + 'Hours';
Office hour : 9 to 5 pm
Output :
intime = 01/01/2013 9:00 AM
out time = 03/01/2013 10:00 PM
Note; 2/1/2103 is holiday
Expected output is : 16 hours
My question is :
If we added the holiday by using the setup, how to reduce that holiday
hours?
Thanks
Best Answer
Pleasee use following code: