Skip to main content

Hi everyone, 

 

I'm trying to implement a custom emergency dispatch process in Salesforce Field Service using Apex, and I'm looking for guidance on whether it's possible to replicate the behaviour of the Emergency Scheduling Wizard. 

 

For an emergency Service Appointment, I need to:

  • Find the nearest Field Service Technician (Service Resource).
  • Assign the Service Appointment to that technician even if they already have an existing appointment (allow overlapping appointments).
  • Pin the Service Appointment.
  • Automatically dispatch the appointment.

Current Behaviour: 

 

I'm currently using an Emergency Scheduling Policy to retrieve available slots. However, it only returns technicians who have available capacity or free time slots. 

 

If the nearest technician already has an appointment, they isn't returned by the scheduling APIs, even though our business requirement is to assign the emergency appointment to that technician by allowing an overlap. 

 

Reference:

 

I'm referring to the Salesforce documentation for Emergency Scheduling: 

https://help.salesforce.com/s/articleView?id=service.pfs_emergency.htm&type=5

 

 

Questions:

  1. How does the Emergency Scheduling Wizard determine the nearest technician?
  2. Does it use internal logic that isn't exposed through the standard Field Service scheduling APIs?
  3. Is there a supported Apex or Field Service API that can return the nearest Service Resource regardless of existing appointments?
  4. Has anyone successfully implemented this scenario in Apex?
  5. What is the Salesforce-recommended approach for reproducing the Emergency Scheduling Wizard behaviour programmatically?

Ultimately, we're trying to build a custom Apex solution that behaves the same as the Emergency Scheduling Wizard, but we're unable to retrieve the nearest technician when they already have scheduled work. 

 

Any guidance, recommended approach, or experience with this scenario would be greatly appreciated. 

 

Thanks in advance!

3 réponses
  1. 26 juil., 22:47

    Yash, if you want to find nearest true location of the technician to the Service Appointment based on their current pinged location from their SFS mobile app - you can use the following fields:  

     

    LastKnownLatitude | TypedoublePropertiesCreate, Filter, Nillable, Sort, UpdateDescriptionThe latitude of the last known location. 

     

    LastKnownLongitude | TypedoublePropertiesCreate, Filter, Nillable, Sort, UpdateDescriptionThe longitude of the last known location. 

     

    The last known location is based on the frequency that you set in the Field Service Mobile settings in which they ping their location breadcrumb..  

     

    What I would do is a 2 step process - 1st - fetch the filtered list of resources through the other apex methods to make sure I get resources based on the minimum Scheduling policy work rules requirement - example - match territory, match skills.. based on the filtered list - you can - on a subset of resources use the last known location to find the nearest resources, there are distance functions in apex where you can find the nearest tech through the "As the crow flies" model and not SLR.  The more resources you query the distance the more overhead you would have in calculating this distance.. Once you find the nearest tech, manually create the assignment by creating an AssignedResource record manually - since there is no automated scheduling method which will allow you to create overlaps.

0/9000