Loading
Upcoming Mandatory Changes to Public Key Infrastructure (PKI)Read More
Agentforce Field Service and Operations
Table of Contents
Select Filters

          No results
          No results
          Here are some search tips

          Check the spelling of your keywords.
          Use more general search terms.
          Select fewer filters to broaden your search.

          Search all of Salesforce Help
          Guidelines for Avoiding Apex CPU Timeouts in Field Service

          Guidelines for Avoiding Apex CPU Timeouts in Field Service

          Apex CPU timeout is a common limit that is sometimes reached during the Appointment Booking or Candidates actions. This timeout occurs when too many available candidates or too many scheduling slots are provided for appointment booking.

          Required Editions

          Available in: both Salesforce Classic (not available in all orgs) and Lightning Experience
          The Agentforce Field Service and Operations core features, managed package, and mobile app are available in Enterprise, Unlimited, and Developer Editions.

          Package icon This is a Field Service managed package feature.

          The more scheduling slot options available, the more processing time is required to validate each option according to every work rule in the scheduling policy and to grade each option by each of the objectives in the scheduling policy.

          When you call an Appointment Booking or Get Candidates action using the Apex API, the custom code before and after the API call can also cause this Apex CPU timeout. We recommend trying to optimize this code and avoid long processing time.

          To prevent Apex CPU timeouts during Appointment Booking or Get Candidates actions:

          • Enable Enhanced Scheduling and Optimization at least for the territories that get the Apex CPU timeout exception. Enhanced Scheduling and Optimization calculates the time slots in a service outside the Salesforce org where no CPU timeout limits apply.
          • Filter out as many candidates as possible using more Database work rules in your scheduling policy. Database rules are applied at the SOQL query clause level. These rules immediately disqualify resources and query only the resources that you need, so performance isn’t impacted. The database work rule types include:
          • Reduce the horizon of the Appointment Booking and Get Candidates operations. You can change the horizon per service appointment by decreasing the gap between the Due Date and the Earliest Start Time, or it can be changed for all your users in Field Service Settings under Scheduling in the General Logic tab. Select the maximum days to get candidates or book an appointment.
          • For Appointment Booking, reduce the number of time slots in the operating hours used for appointment booking.
          • Enable async logic for problematic service appointments by selecting Use Async Logic on the service appointment, available when you’re not using Enhanced Scheduling and Optimization. Using async logic ensures the Appointment Booking calculation runs in a future job with more CPU time, though the duration to retrieve slots isn’t guaranteed. Future jobs run when the platform decides to do so, such that these jobs can be held in the queue for some time. The slots aren’t returned in the same transaction. The job creates an FSL operation object that helps get the results when you’re using the OOTB FSL actions for Appointments Booking or Get Candidates. If you’re using custom code for these actions, some development can be required to enable you to get the slots when using async logic.
          • Enable Limit Apex Operations in Field Service Settings, available when you’re not using Enhanced Scheduling and Optimization. Limiting Apex operations restricts processing time for the specific scheduling operation, terminating the process when the specified percentage of the timeout limits is reached. The outcome comprises results that have completed processing within the stipulated timeframe. The OOTB UI and API clearly indicate partial processing of results, including the number of service resources completed and the total count of resources involved.
           
          Loading
          Salesforce Help | Article