## TL;DR

The SOQL query ran longer than the two-minute limit. Narrow it: add selective filters on indexed fields, shrink the date range, or break it into smaller queries.

## Error

```text
QUERY_TIMEOUT: Your query request was running for too long
```

## Steps

1. Add a selective filter on an indexed field (Id, Name, CreatedDate) Expected: the query plan becomes selective.
2. Shrink the date range or add LIMIT and page Expected: less work per query.
3. Check the query plan in the developer console Expected: you see the cost.
4. Re-run the narrowed query Expected: it finishes in time.

## When to use

- QUERY_TIMEOUT on SOQL
- The query scans too much

## When not to use

- The query is selective but still times out (then check for locks)
- You need the full table (then use Bulk API instead)

## Tool compatibility

- SOQL selectivity and query plans
- Bulk API for large extracts

## Variant phrasings

### soql query timeout

Add selective filters on indexed fields. The two-minute limit is strict.

### query request running too long

Same: narrow the query or switch to Bulk API.

## Why it happens

Agents write SELECT * style queries with no filters because they want everything. Salesforce kills anything over two minutes.

## Edge cases

- Non-selective filters on large tables always time out; custom indexes help
- Querying the recycle bin (ALL ROWS) is slower

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_2FJXNSVYSwMO-uN4kNwflw
