Newer Version Available
LightningScheduler Class
Namespace
LightningScheduler Methods
These methods are for LightningScheduler. All
methods are static.
createServiceAppointment(createServiceAppointmentInput)
Create a service appointment.
API Version
53.0
Requires Chatter
No
Signature
public static ConnectApi.ServiceAppointmentOutput createServiceAppointment(ConnectApi.CreateServiceAppointmentInput createServiceAppointmentInput)
Parameters
- createServiceAppointmentInput
- Type: ConnectApi.CreateServiceAppointmentInput
- Input parameters to create a service appointment.
Return Value
Usage
Considerations for using engagement channel types with the service-appointments resource:
- Enable Schedule Appointments Using Engagement Channels in Salesforce Scheduler Settings in your Salesforce org.
- When you create or modify appointments, shifts must be defined in the scheduling policy. For more information on setting up shifts in the scheduling policy, see Define Shift Rules in Scheduling Policy.
- When you use engagement channel type and shifts to create a service appointment, Salesforce Scheduler considers the default value for the Appointment Type (if not specified). However, Salesforce Scheduler only considers the engagement channel type and Appointment Type is ignored.
Example
For an account (existing user):
1ConnectApi.ExtendedFieldInput extendedFieldEmail = new ConnectApi.ExtendedFieldInput();
2extendedFieldEmail.name = 'Email';
3extendedFieldEmail.value = 'rachael.adams@salesforce.com';
4
5ConnectApi.ExtendedFieldInput extendedFieldPhone = new ConnectApi.ExtendedFieldInput();
6extendedFieldPhone.name = 'Phone';
7extendedFieldPhone.value = '1234567890';
8
9List<ConnectApi.ExtendedFieldInput> extendedFieldList = new List<ConnectApi.ExtendedFieldInput>();
10extendedFieldList.add(extendedFieldEmail);
11extendedFieldList.add(extendedFieldPhone);
12
13ConnectApi.ServiceAppointmentInput serviceAppInput = new ConnectApi.ServiceAppointmentInput();
14serviceAppInput.extendedFields = extendedFieldList;
15serviceAppInput.engagementChannelTypeId = '0eFRM00000000Bv2AI';
16serviceAppInput.serviceTerritoryId = '0Hhxx0000004C92CAE';
17serviceAppInput.workTypeId = '08qxx0000004C92AAE';
18serviceAppInput.parentRecordId = '001xx000003GYR1AAO';
19serviceAppInput.schedStartTime = DateTime.valueOf('2021-05-28 12:15:00');
20serviceAppInput.schedEndTime = DateTime.valueOf('2021-05-28 12:45:00');
21serviceAppInput.appointmentMode = 'Group';
22serviceAppInput.attendeeLimit = 20;
23
24ConnectApi.AssignedResourcesInput asResourceInput = new ConnectApi.AssignedResourcesInput();
25asResourceInput.serviceResourceId = '0Hnxx0000004CAiCAM';
26asResourceInput.isRequiredResource = true;
27asResourceInput.isPrimaryResource = true;
28
29List<ConnectApi.AssignedResourcesInput> asResourceInputList = new List<ConnectApi.AssignedResourcesInput>();
30asResourceInputList.add(asResourceInput);
31
32ConnectApi.CreateServiceAppointmentInput createInput = new ConnectApi.CreateServiceAppointmentInput();
33createInput.serviceAppointment = serviceAppInput;
34createInput.assignedResources = asResourceInputList;
35
36try{
37 ConnectApi.ServiceAppointmentOutput appointmentResult = ConnectApi.LightningScheduler.createServiceAppointment(createInput);
38 String serviceAppointmentId = appointmentResult.result.serviceAppointmentId;
39 List<String> assignedResourceIds = appointmentResult.result.assignedResourceIds;
40}catch(ConnectApi.ConnectApiException ex){
41 //Handle Exception
42}For a lead (authenticated guest user):
1ConnectApi.LeadInput leadInput = new ConnectApi.LeadInput();
2leadInput.firstName = 'Rachel';
3leadInput.lastName = 'Adams';
4leadInput.phone = '012-345-6789';
5leadInput.email = 'rachel.adams@salesforce.com';
6leadInput.company = 'Salesforce';
7
8ConnectApi.ExtendedFieldInput extendedFieldEmail = new ConnectApi.ExtendedFieldInput();
9extendedFieldEmail.name = 'Email';
10extendedFieldEmail.value = 'rachael.adams@salesforce.com';
11
12ConnectApi.ExtendedFieldInput extendedFieldPhone = new ConnectApi.ExtendedFieldInput();
13extendedFieldPhone.name = 'Phone';
14extendedFieldPhone.value = '1234567890';
15
16List<ConnectApi.ExtendedFieldInput> extendedFieldList = new List<ConnectApi.ExtendedFieldInput>();
17extendedFieldList.add(extendedFieldEmail);
18extendedFieldList.add(extendedFieldPhone);
19
20ConnectApi.ServiceAppointmentInput serviceAppInput = new ConnectApi.ServiceAppointmentInput();
21serviceAppInput.extendedFields = extendedFieldList;
22serviceAppInput.engagementChannelTypeId = '0eFRM00000000Bv2AI';
23serviceAppInput.serviceTerritoryId = '0Hhxx0000004C92CAE';
24serviceAppInput.workTypeId = '08qxx0000004C92AAE';
25serviceAppInput.schedStartTime = DateTime.valueOf('2021-05-28 12:15:00');
26serviceAppInput.schedEndTime = DateTime.valueOf('2021-05-28 12:45:00');
27
28ConnectApi.AssignedResourcesInput asResourceInput = new ConnectApi.AssignedResourcesInput();
29asResourceInput.serviceResourceId = '0Hnxx0000004CAiCAM';
30asResourceInput.isRequiredResource = true;
31asResourceInput.isPrimaryResource = true;
32
33List<ConnectApi.AssignedResourcesInput> asResourceInputList = new List<ConnectApi.AssignedResourcesInput>();
34asResourceInputList.add(asResourceInput);
35
36ConnectApi.CreateServiceAppointmentInput createInput = new ConnectApi.CreateServiceAppointmentInput();
37createInput.serviceAppointment = serviceAppInput;
38createInput.assignedResources = asResourceInputList;
39createInput.lead = leadInput;
40
41try{
42 ConnectApi.ServiceAppointmentOutput appointmentResult = ConnectApi.LightningScheduler.createServiceAppointment(createInput);
43 String serviceAppointmentId = appointmentResult.result.serviceAppointmentId;
44 List<String> assignedResourceIds = appointmentResult.result.assignedResourceIds;
45}catch(ConnectApi.ConnectApiException ex){
46 //Handle Exception
47}updateServiceAppointment(updateServiceAppointmentInput)
Update a service appointment.
API Version
53.0
Requires Chatter
No
Signature
public static ConnectApi.ServiceAppointmentOutput updateServiceAppointment(ConnectApi.UpdateServiceAppointmentInput updateServiceAppointmentInput)
Parameters
- updateServiceAppointmentInput
- Type: ConnectApi.UpdateServiceAppointmentInput
- Input parameters to update a service appointment.
Return Value
Usage
Considerations for using engagement channel types with the service-appointments resource:
- Enable Schedule Appointments Using Engagement Channels in Salesforce Scheduler Settings in your Salesforce org.
- When you create or modify appointments, shifts must be defined in the scheduling policy. For more information on setting up shifts in the scheduling policy, see Define Shift Rules in Scheduling Policy.
- When you use engagement channel type and shifts to modify an appointment, Salesforce Scheduler considers the default value for the Appointment Type (if not specified). However, Salesforce Scheduler only considers the engagement channel type and Appointment Type is ignored.
Example
1ConnectApi.ExtendedFieldInput extendedFieldEmail = new ConnectApi.ExtendedFieldInput();
2extendedFieldEmail.name = 'Email';
3extendedFieldEmail.value = 'rachel.adams@salesforce.com.example';
4
5ConnectApi.ExtendedFieldInput extendedFieldPhone = new ConnectApi.ExtendedFieldInput();
6extendedFieldPhone.name = 'Phone';
7extendedFieldPhone.value = '0123456789';
8
9ConnectApi.ExtendedFieldInput extendedFieldStatus = new ConnectApi.ExtendedFieldInput();
10extendedFieldStatus.name = 'Status';
11extendedFieldStatus.value = 'None';
12
13List<ConnectApi.ExtendedFieldInput> extendedFieldList = new List<ConnectApi.ExtendedFieldInput>();
14extendedFieldList.add(extendedFieldEmail);
15extendedFieldList.add(extendedFieldPhone);
16extendedFieldList.add(extendedFieldStatus);
17
18ConnectApi.ServiceAppointmentInput serviceAppInput = new ConnectApi.ServiceAppointmentInput();
19serviceAppInput.extendedFields = extendedFieldList;
20serviceAppInput.serviceTerritoryId = '0Hhxx0000004C92CAE';
21serviceAppInput.workTypeId = '08qxx0000004C92AAE';
22serviceAppInput.schedStartTime = DateTime.valueOf('2021-05-28 12:15:00');
23serviceAppInput.schedEndTime = DateTime.valueOf('2021-05-28 12:45:00');
24
25ConnectApi.AssignedResourcesInput asResourceInput = new ConnectApi.AssignedResourcesInput();
26asResourceInput.serviceResourceId = '0Hnxx0000004CAiCAM';
27asResourceInput.isRequiredResource = true;
28asResourceInput.isPrimaryResource = true;
29
30//Multi-resource
31ConnectApi.AssignedResourcesInput asResourceInputReq = new ConnectApi.AssignedResourcesInput();
32asResourceInputReq.serviceResourceId = '0Hnxx0000004CAgCAM';
33asResourceInputReq.isRequiredResource = true;
34asResourceInputReq.isPrimaryResource = false;
35
36List<ConnectApi.AssignedResourcesInput> asResourceInputList = new List<ConnectApi.AssignedResourcesInput>();
37asResourceInputList.add(asResourceInput);
38asResourceInputList.add(asResourceInputReq);
39
40ConnectApi.UpdateServiceAppointmentInput updateInput = new ConnectApi.UpdateServiceAppointmentInput();
41updateInput.serviceAppointment = serviceAppInput;
42updateInput.assignedResources = asResourceInputList;
43updateInput.serviceAppointmentId = '08pxx0000004CYqAAM';
44
45try{
46 ConnectApi.ServiceAppointmentOutput appointmentResult = ConnectApi.LightningScheduler.updateServiceAppointment(updateInput);
47 String serviceAppointmentId = appointmentResult.result.serviceAppointmentId;
48 List<String> assignedResourceIds = appointmentResult.result.assignedResourceIds;
49}catch(ConnectApi.ConnectApiException ex){
50 //Handle Exception
51}