Newer Version Available

This content describes an older version of this product. View Latest

SchedulerResources Class

Contains methods that holds the business logic to get resources availability.

Namespace

LxScheduler

Implementation Considerations

Apex implementation of the methods in the SchedulerResources class should adhere to Apex Governor Limits. It includes synchronous heap size limit, synchronous CPU time limit, and synchronous concurrent transactions for long running transactions. To avoid governor limits, you must tune the input by reducing the time frame, limiting number of service resources, or limiting number or territories at a time. This will reduce the overall transaction time and response size of the implementation. For more information on standard Apex Governer Limits, see Salesforce Developer Limits and Allocations Quick Reference.

Example

To get list of available service resources (appointment candidates):

1String response = lxscheduler.SchedulerResources.getAppointmentCandidates(input);

To get a list of available appointment time slots for a resource:

1String response = lxscheduler.SchedulerResources.getAppointmentCandidates(input);

SchedulerResources Methods

The following are methods for SchedulerResources.

getAppointmentCandidates(getAppointmentCandidatesInput)

Returns a list of available service resources.

Signature

public static String getAppointmentCandidates(lxscheduler.GetAppointmentCandidatesInput getAppointmentCandidatesInput)

Parameters

getAppointmentCandidatesInput
Type: lxscheduler.GetAppointmentCandidatesInput
This method takes input as an instance of the lxscheduler.GetAppointmentCandidatesInput class. Build the instance of the input class using the lxscheduler.GetAppointmentCandidatesInputBuilder class.

Return Value

Type: String

getAppointmentSlots(getAppointmentSlotsInput)

Returns a list of available appointment time slots for a resource based on given work type group and territories.

Signature

public static String getAppointmentSlots(lxscheduler.GetAppointmentSlotsInput getAppointmentSlotsInput)

Parameters

getAppointmentSlotsInput
Type: lxscheduler.GetAppointmentSlotsInput
This method takes input as an instance of the lxscheduler.GetAppointmentSlotsInput class. Build the instance of the input class using the lxscheduler.GetAppointmentSlotsInputBuilder class.

Return Value

Type: String

setAppointmentCandidatesMock(expectedResponse)

Sets a mock object when running tests for the getAppointmentCandidates method.

This constructor is intended for test usage and throws an exception if used outside of the Apex test context.

Signature

public static void setAppointmentCandidatesMock(String expectedResponse)

Parameters

expectedResponse
Type: String

Return Value

Type: void

This example shows a sample implementation of the GetAppointmentCandidates class:

1public class AppointmentCandidateService {
2   //Instance members for parsing
3   public String startTime;
4   public String endTime;
5   public List<String> resources; 
6   public String territoryId;
7   public static List<AppointmentCandidateService> getAppointmentCandidates(){
8      //Build input for GetAppointmentCandidates API
9      lxscheduler.GetAppointmentCandidatesInput input = new lxscheduler.GetAppointmentCandidatesInputBuilder()
10         .setWorkTypeGroupId('0VSRM0000000AGT4A2')
11         .setTerritoryIds(new List<String>{'0HhRM0000000G8W0AU'})
12         .setStartTime(System.now().format('yyyy-MM-dd\'T\'HH:mm:ssZ','America/Los_Angeles'))
13         .setEndTime(System.now().addDays(2).format('yyyy-MM-dd\'T\'HH:mm:ssZ','America/Los_Angeles'))
14         .setSchedulingPolicyId('0VrRM00000000D0')
15         .setApiVersion(Double.valueOf('50.0'))
16         .build();
17      List<AppointmentCandidateService> vList = parse(lxscheduler.SchedulerResources.getAppointmentCandidates(input));
18      return vList;
19   }
20   private static List<AppointmentCandidateService> parse(String json) {
21      return (List<AppointmentCandidateService>) System.JSON.deserialize(json, List<AppointmentCandidateService>.class);
22   }
23}

This example shows how to set a sample mock using the setAppointmentCandidatesMock method:

1@isTest
2private class GetAppointmentCandidatesTest {
3   static testMethod void getAppCandidatesTest() {
4      String expectedResponse = '[' +
5                                    '  {' +
6                                    '    \"startTime\": \"2021-03-18T16:00:00.000+0000\",' +
7                                    '    \"endTime\": \"2021-03-18T17:00:00.000+0000\",' +
8                                    '    \"resources\": [' +
9                                    '      \"0HnRM0000000Fxv0AE\"' +
10                                    '    ],' +
11                                    '    \"territoryId\": \"0HhRM0000000G8W0AU\"' +
12                                    '  },' +
13                                    '  {' +
14                                    '    \"startTime\": \"2021-03-18T19:00:00.000+0000\",' +
15                                    '    \"endTime\": \"2021-03-18T20:00:00.000+0000\",' +
16                                    '    \"resources\": [' +
17                                    '      \"0HnRM0000000Fxv0AE\"' +
18                                    '    ],' +
19                                    '    \"territoryId\": \"0HhRM0000000G8W0AU\"' +
20                                    '  }' +
21                                    ']';
22      lxscheduler.SchedulerResources.setAppointmentCandidatesMock(expectedResponse);
23
24      Test.startTest();
25         List<AppointmentCandidateService> candidateList = AppointmentCandidateService.getAppointmentCandidates();
26         System.assertEquals(2, candidateList.size(), 'Should return only 2 records!');
27      Test.stopTest();
28   }
29}

setAppointmentSlotsMock(expectedResponse)

Sets a mock object when running tests for the getAppointmentSlots method.

This constructor is intended for test usage and throws an exception if used outside of the Apex test context.

Signature

public static void setAppointmentSlotsMock(String expectedResponse)

Parameters

expectedResponse
Type: String

Return Value

Type: void