Level up any Communications Cloud implementation by allowing customers to book service appointments through your community site. Communications Cloud, Experience Cloud, and Salesforce Field Service can be integrated to greatly increase productivity and customer engagement in your self-service process.
Imagine a scenario where a customer orders products from your Experience Site. The next step would be for a technician to install the purchased product. Instead of having a dispatcher schedule the appointment, why not allow the customer to choose a time during the checkout process? This not only removes a manual task for the dispatcher but also reduces the number of appointment cancellations based on the customer’s availability.
Although there are many paid options available in the Salesforce ecosystem to facilitate self-service, we will explore a way to use components from Experience Cloud, Salesforce Field Service, and Core to meet this need. Palladin Technologies has extensive expertise in helping businesses implement such integrated solutions, ensuring seamless and effective use of Salesforce tools.
Note: The following packages are needed to utilize this feature
- Vlocity Communications Cloud
- Experience Cloud
- Salesforce Field Service
Base Record Creation:
- Create a Screen Flow:
-
- The Screen Flow will contain the screens and logic to create all of the necessary records and schedule the service appointment.
-
- Based on your data model, create all necessary parent records for the service appointment, using the Create Records Element.
-
- Optional: Utilize screens for any customer input needed when creating the records.
-
- Create the service appointment using the Create Records element.
SFS Managed Package Components:
The Salesforce Field Service managed package namespace provides many classes that can be used for appointment booking. A description of all classes can be found here: Field Service Developer Guide – FSL Apex Namespace
For this scenario, we will be using three of the classes in the SFS namespace. These classes are:
- AppointmentBookingService
- ScheduleService
- ScheduleResult
Retrieving the available time slots:
- The first step in the appointment booking process is to retrieve the available time slots from the SFS scheduler. To do this, we will be leveraging the getSlots method in the AppointmentBookingService class.
-
- Note: Since all of these classes are in the Salesforce Field Service managed package namespace, we must append each call with FSL.
- For example: FSL.AppointmentBookingService.getSlots();
- Note: Since all of these classes are in the Salesforce Field Service managed package namespace, we must append each call with FSL.
- The following parameters are required when calling the getSlots method:
-
- serviceID
- Data Type: Id
- The ID of the service appointment being scheduled
- policyId
- Data Type: Id
- The ID of the scheduling policy being used
- operatingHoursId
- Data Type: Id
- The ID of the operating hours record used to determine time slot intervals
- tz
- Data Type: System.TimeZone
- The time zone in which the slots are returned. This time zone must be the time zone of the service territory in which the service appointment is performed. If any other time zone is used, the appointment booking slots are converted to the service territory time zone at run time
- exactAppointment
- Data Type: Boolean
- Specifies whether the result uses exact appointments or an arrival window. When the getSlots() method is called, the exactAppointment value on the work type is ignored
- Sample Code:
- List<FSL.AppointmentBookingSlot> slots = FSL.AppointmentBookingService.getSlots(sa.Id, schedulingPolicyId, operatingHoursId, tz, false);
- serviceID
- This is just one variation of a call to the getSlots method. A full description of each variation can be found here:
Field Service Developer Guide – Appointment Booking Service - The result of the call to the getSlots method is a list of FSL.AppointmentBookingSlot
-
- This object is comprised of the following fields:
- Grade = the grade of the slot returned by the scheduling engine
- Interval = represents the time slot
- Interval.Start = the start time of the time slot
- Interval.Finish = the end time of the time slot
- This object is comprised of the following fields:
- To return your results to the Screen flow, we must serialize each FSL.AppointmentBookingSlot. Below is an example of how to do this:
-
- public class Interval {
public Datetime start;
public Datetime finish;
}
@invocableMethod()
public static List String getAppointmentSlots(<Input Parameters>){
List<Objec> slotJson = new List<Object>();
List<FSL.AppointmentBookingSlot> slots = FSL.AppointmentBookingService.getSlots(sa.Id, schedulingPolicyId, operatingHoursId, tz, false);
for(FSL.AppointmentBookingSlot appSlot : slots){
Map<String,Object> indSlot = new Map<String, Object>();
indSlot.put(‘grade’, appSlot.grade);
Interval timeSlotInterval = new Interval();
timeSlotInterval.start = appSlot.interval.Start;
timeSlotInterval.finish = slot.interval.Finish;
indSlot.put(‘interval’, timeSlotInterval);
slotJson.add(indSlot);
}
return JSON.serialize(slotJson);
}
- public class Interval {
Displaying available time slots to the User:
The next step in the process is to show the available slots to the user. Utilize the following steps to accomplish this:
- Display the available time slots to the user
-
- Add the Screen Element to your flow.
- In the screen element, add the Appointment Scheduling Component provided by the Salesforce Field Service managed package.
- Fill in the following parameters on the Appointment Scheduling Component:
- Required:
- bookingError:
- A custom error message to display to the user if appointment booking fails.
- operatingHoursId:
- The Operating Hours used to retrieve the time slots.
- policyId:
- The Scheduling Policy used to retrieve the time slots.
- serviceAppointment:
- The Service Appointment record that you are booking.
- slotJson:
- The serialized JSON returned from your getSlots call.
- bookingError:
- Optional:
- calendarStartDate:
- The earliest available date shown to the user.
- timeSlotBegin
- The selected time slot start time.
- timeSlotFinish
- The selected time slot end time.
- Store the output of the time slot selected by the user:
- Create variables to store the output from the Appointment Scheduling component.
- These variables will be used to update the Service Appointment record later in the flow.
- calendarStartDate:
- Required:
Scheduling the Service Appointment:
The final step in scheduling the service appointment is to set the appointment. To accomplish this, we will be using the FSL.ScheduleResult class and the FSL.ScheduleService class in the Salesforce Field Service namespace.
- Update the Appointment ArrivalWindowStartTime and ArrivalWindowEndTime fields.
-
- Before updating the fields, we need to do a timezone conversion based on the Operating Hours used to schedule. Use the following code to convert the timeslotbegin and timeslotend to the correct timezone.
- Timezone tz = Timezone.getTimeZone(<timezone from Operating Hours>);
- Appointment.ArrivalWindowStartTime = timeslotbegin.addSeconds(tz.getOffset(Appointment[0].timeslotbegin) / -1000);
- Appointment.ArrivalWindowEndTime = timeslotend.schEnd.addSeconds(tz.getOffset(timeslotend) / -1000);
- Using the Update Records element, set these two fields on the appointment with the timeslotBegin and timeslotFinish variables returned from the Appointment Scheduling Screen Element.
- Before updating the fields, we need to do a timezone conversion based on the Operating Hours used to schedule. Use the following code to convert the timeslotbegin and timeslotend to the correct timezone.
- Call the FSL.ScheduleService class to schedule the appointment.
-
- Create an Apex class with an invocable method.
- Pass the SchedulingPolicy Id that was used to get the time slots and the Service Appointment Id to the invocable method.
- Call the schedule method in the FSL.ScheduleService class to book your appointment. The return type is an instance of the FSL.ScheduleResult class. The results Below is an example code snippet of this call:
- FSL.ScheduleResult scheduleResult = FSL.ScheduleService.schedule(schedulingPolicyId, serviceAppointmentId);
- Once you have made a successful call to the FSL.ScheduleService.schedule method, the results will be stored in an instance of the FSL.ScheduleResult class. This class is comprised of the following parameters:
-
- Grade
- The grading results of the slot
- Resource
- The Service Resource chosen for the timeslot
- Service
- The Service Appointment Object
- Grade
You can leverage the above fields to validate that the appointment was booked and display the results to the user.
Wrapping Up:
After implementing these steps, you have a Flow ready to be exposed to Experience Cloud users for self-service scheduling. This approach enables you to establish a seamless and efficient appointment booking process, ultimately enhancing productivity and customer engagement.
Learn More About Partnering With Us!
Senior Software Developer
Ryan Reddish is a Senior Software Developer at Palladin Technologies, specializing in Salesforce development. He holds a degree in Management Information Systems from the University of Alabama. Ryan possesses a robust technical skill set, including proficiency in Salesforce, Apex, SOQL, VisualForce, Lightning Component Framework, JavaScript, HTML, Java, REST, Git, and Copado. His comprehensive expertise and strong educational background make him an integral part of the Palladin Technologies team, driving innovative solutions and technical excellence.