Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
Support Classes
Working with Business Hours
Business hours are used to specify the hours at which your customer support team operates, including multiple business hours in multiple time zones.
1// Get the default business hours
2BusinessHours bh = [SELECT Id FROM BusinessHours WHERE IsDefault=true];
3
4// Create Datetime on May 28, 2008 at 1:06:08 AM in local timezone.
5Datetime startTime = Datetime.newInstance(2008, 5, 28, 1, 6, 8);
6
7// Find the time it will be one business hour from May 28, 2008, 1:06:08 AM using the
8// default business hours. The returned Datetime will be in the local timezone.
9Datetime nextTime = BusinessHours.add(bh.id, startTime, 60 * 60 * 1000L);1// Get the default business hours
2BusinessHours bh = [SELECT Id FROM BusinessHours WHERE IsDefault=true];
3
4// Create Datetime on May 28, 2008 at 1:06:08 AM in local timezone.
5Datetime startTime = Datetime.newInstance(2008, 5, 28, 1, 6, 8);
6
7// Find the time it will be one business hour from May 28, 2008, 1:06:08 AM using the
8// default business hours. The returned Datetime will be in GMT.
9Datetime nextTimeGmt = BusinessHours.addGmt(bh.id, startTime, 60 * 60 * 1000L);1// Get the default business hours
2BusinessHours bh = [select id from businesshours where IsDefault=true];
3
4// Create Datetime on May 28, 2008 at 1:06:08 AM in local timezone.
5Datetime startTime = Datetime.newInstance(2008, 5, 28, 1, 6, 8);
6
7// Create Datetime on May 28, 2008 at 4:06:08 PM in local timezone.
8Datetime endTime = Datetime.newInstance(2008, 5, 28, 16, 6, 8);
9
10// Find the number of business hours milliseconds between startTime and endTime as
11// defined by the default business hours. Will return a negative value if endTime is
12// before startTime, 0 if equal, positive value otherwise.
13Long diff = BusinessHours.diff(bh.id, startTime, endTime);Working with Cases
Incoming and outgoing email messages can be associated with their corresponding cases using the Cases class getCaseIdFromEmailThreadId method. This method is used with Email-to-Case, which is an automated process that turns emails received from customers into customer service cases.
The following example uses an email thread ID to retrieve the related case ID.
1public class GetCaseIdController {
2
3 public static void getCaseIdSample() {
4 // Get email thread ID
5 String emailThreadId = '_00Dxx1gEW._500xxYktg';
6 // Call Apex method to retrieve case ID from email thread ID
7 ID caseId = Cases.getCaseIdFromEmailThreadId(emailThreadId);
8
9 }
10}