Loading

Error "Too many query rows: 50001" when running Field Service Health Check with Horizon Based Validations

Data pubblicazione: Jul 3, 2026
Descrizione
Problem

When running the Field Service Health Check on the Horizon Based Validations tab, the operation fails with the error Too many query rows: 50001. This prevents the Health Check from completing, even when a single territory is selected. The issue typically begins or worsens after increasing the optimization threshold or expanding the horizon window.

 
Cause

Salesforce enforces a limit of 50,000 rows per single Apex query. The Horizon Based Validations page executes multiple aggregated queries across ServiceAppointment, ServiceTerritoryMember, Shift, and related objects. When the total ServiceAppointment record count within a territory's horizon window exceeds 50,000 rows, the combined query result set triggers the governor limit exception.

This is most common in orgs with large service territories, extended horizon windows, or high volumes of historical ServiceAppointment records — including completed and cancelled records.

NOTE: To check the ServiceAppointment volume in your org, run the following SOQL query in Developer Console:
SELECT COUNT(Id) FROM ServiceAppointment WHERE ServiceTerritory.Name = '<your-territory-name>' AND EarliestStartTime <= TODAY AND DueDate >= TODAY
If the result exceeds 50,000, the Health Check will fail. If it is close to the limit (e.g., 45,000+), consider implementing a resolution strategy below to provide headroom for future growth.
Risoluzione

The Health Check fails because too many ServiceAppointment rows are queried within the horizon window. Use the immediate workaround below, then apply one or more long-term strategies to permanently resolve the issue.

Immediate Workaround — Filter by Unscheduled

  1. Open the Field Service Health Check (Horizon Based Validations tab).
  2. Select your territory.
  3. Check the Filter Services By: Unscheduled checkbox.
  4. Click Run Health Check.


This excludes already-scheduled ServiceAppointments from the query, reducing the row count below the 50,000-row threshold.

NOTE: This workaround does NOT validate scheduled appointments. Use it to confirm territory setup while planning long-term data cleanup.


Long-Term Strategies

  1. Archive or delete completed records — Remove old, completed, or cancelled ServiceAppointments that fall within the horizon window. This is the most direct way to reduce query row count. Review your org's data retention policy before bulk deletion.
  2. Add a Match Territory Work Rule — Add a Work Rule with type Match Territory to your Scheduling Policy. This filters the scope of ServiceTerritoryMembers evaluated during Health Check execution, reducing related records queried — without deleting data.
    • Open your Scheduling Policy in Field Service.
    • Add a new Work Rule of type Match Territory.
    • Configure it to match the service territory of each appointment.
  3. Reduce the horizon window — Narrow the date range evaluated by the Health Check. For example, reducing from 30 days to 14 or 7 days queries fewer ServiceAppointments.
  4. Establish retention policies — Set or tighten ServiceAppointment retention policies to prevent future accumulation. Archive or delete completed appointments on a regular schedule (e.g., quarterly or annually).


NOTE: Archiving or deleting ServiceAppointments is permanent — ensure your retention policy aligns with business and compliance requirements before proceeding. Reducing the horizon window may also cause the Health Check to miss optimization opportunities for appointments beyond the new window.
Numero articolo Knowledge

005387654

 
Caricamento
Salesforce Help | Article