function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Lucy YuanLucy Yuan 

How to query the busniess hours base on cases in one SOQL?

Hi

i need to query business hours base on cases in one SOQL.

 

Maybe i need to get one map<BusinessHour , Case> ? but how to get this kind of map when i get the all cases ? That means i need get business hour of  every case ????

 

Hope to hear from you asap :)

*werewolf**werewolf*

I'm not really sure what you're asking for.  If you just want to find out what Business Hours a case is associated to, there's a field called BusinessHoursId on Case which is a reference to the Business Hours object.  If you are not seeing that field, check your field level security -- by default it's not set to visible for all profiles.

BA_AdminBA_Admin

Lucy,

    Iam not sure if i got you right, but there is one app called Case Age in Business Hours, it calculates the hours spent for each and every case based on your ORG business hours.

Lucy YuanLucy Yuan

Thank you !

in fact ,  before i want to get more field on business hour to calculate the SLA due time for every status.

 

ie. if case status is "solution communicated" so this case should be push to next status "solution execute" during 48 work hours from the creating time . so it need to considerate the bussiness hours.

i found the solution  BusinessHour obj has those kind of methods.

 

// Get the default business hours
BusinessHours bh = [select id from businesshours where IsDefault=true];
// Create Datetime on May 28, 2008 at 1:06:08 AM in local timezone.
Datetime startTime = Datetime.newInstance(2008, 5, 28, 1, 6, 8);
// Find the time it will be one business hour from May 28, 2008, 1:06:08 AM using the
// default business hours. The returned Datetime will be in GMT.
Datetime nextTimeGmt = BusinessHours.addGmt(bh.id, startTime, 60 * 60 * 1000L);

 

so i guess i have got what i need  through those methods. .Maybe you have more esay or more better solution.