## TL;DR
Split the rule before you tune anything else. A Gainsight rule that runs one wide SOQL query across enterprise accounts, contacts, and usage objects will time out in Salesforce long before Gainsight scoring logic is at fault. Narrow the query with selective filters and a shorter window, split the rule by segment, fetch in stages into Gainsight objects, and the same health scores calculate on schedule.

```text
Gainsight rule execution failed SFDC SOQL query timeout: health scores not recalculated for enterprise accounts
```

## Use this when
- The Gainsight rule execution history shows a Salesforce query timeout as the failure reason
- Smaller segments or manual narrow runs of the same rule succeed
- The rule joins several large Salesforce objects or scans years of activity history

## Not for this skill when
- The rule fails instantly with a field or object permission error, which is an access problem, not a timeout
- Salesforce itself is in an incident window affecting all integrations

## Steps
1. Open the failed run in Gainsight Rules Engine execution history and capture the exact step, query, and timeout message, plus how long it ran before failing. Rules often chain several fetches, and only one step usually times out while the rest pass, so do not rewrite the healthy steps. Verify: the failing fetch step and its query shape are identified
2. Measure the Salesforce side. Run a comparable count in Salesforce or a query tool for the objects involved, filtered the way the rule filters them today. Enterprise account sets with unfiltered activity, task, or usage history are the usual volume bombs, especially where the filter field is not indexed or selective, such as a free-text or formula field. Verify: the row volumes per object and the non-selective filter are named
3. Redesign the fetch in stages. Pull accounts first with a selective filter such as record type, active contract status, and a bounded last-modified window, load them to a Gainsight custom object, then fetch related usage and activity only for those account ids in a second rule or step. Staged fetches turn one giant join into several small indexed lookups. Verify: the staged rule processes the same account set with each fetch returning in a fraction of the timeout limit
4. Split execution by segment or region if one tenant still runs hot, and stagger the rule schedule away from other heavy Salesforce jobs such as backups, other integrations, and the nightly sync. Salesforce timeouts are often shared-tenancy timing, so a two hour schedule shift can be a real fix, not a workaround. Verify: each segment rule completes inside its window across three consecutive scheduled runs
5. Re-run the full health score calculation for the enterprise accounts that missed scoring, and compare a sample of twenty accounts against hand-checked Salesforce and usage values so a narrowed filter did not quietly drop accounts from scoring. Verify: sampled scores match hand checks and the scored account count equals the eligible enterprise count
6. Add a rule duration alert in Gainsight that warns when a run passes roughly seventy percent of the historical timeout zone, so the next growth in data volume shows up as a warning week instead of a silent scoring gap for your largest accounts. Verify: the duration alert exists and fires on a test long-running rule

## Why it happens
Salesforce enforces synchronous query timeouts to protect shared resources, and Gainsight rules inherit that limit through the connector. Rule authors build logic against a smaller data set, then enterprise activity and usage history grow until the same query plan crosses the timeout. Because the rule fails as a unit, no scores update, and the failure looks like a Gainsight outage when it is really one unselective query.

Compatibility: Gainsight Rules Engine including Bionic Rules, Salesforce SOQL through the Gainsight connector, and Salesforce selective query and indexing guidance, current versions.

## Variants and edge cases
### Gainsight bionic rule SOQL timeout enterprise
['The Bionic Rules phrasing for the same shape. The fix is still query shape and staging, not retries, because a timed-out query retried unchanged times out again with more load.']

### Salesforce query timeout Gainsight health score stale
['The symptom-first phrasing, where CS notices stale enterprise scores. Work backwards from score freshness per segment to the specific rule run that failed.']

### Gainsight rule fetch step failing large accounts
['The step-level variant. Use execution history to isolate the fetch, because transformation and action steps in the same rule are usually innocent.']

Edge cases to work through before you close the incident:
- Formula fields and fields with leading wildcard text filters cannot be made selective by indexing. Change the filter design, not only the schedule.
- Custom indexes in Salesforce need a support case and a real query plan justification. Stage and split first, they solve most cases without one.
- When you split rules by segment, guard against overlap double-scoring an account. Keep one authoritative segment field and log which rule scored each account.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_6UYYT4j6SKemcNzZTgjPKw
