System.LimitException: Too many query rows: meaning and how to fix it

Governor limits Checked against the official docs on Source: SOAP API Developer Guide: Core Data Types, StatusCode

Quick answer

System.LimitException: Too many query rows: The queries in one transaction returned more rows in total than the governor limit allows. Start with: Filter queries to return only the rows you need and add LIMIT.

Typical message: System.LimitException: Too many query rows: 50001

Cause

The queries in one transaction returned more rows in total than the governor limit allows.

How to fix System.LimitException: Too many query rows

  1. Filter queries to return only the rows you need and add LIMIT.
  2. Process big sets in Batch Apex, which gets fresh limits per batch.

Have a different message? Paste it into the error decoder, which matches it against 45 common Salesforce errors in your browser.

Frequently asked questions

What does System.LimitException: Too many query rows mean in Salesforce?

The queries in one transaction returned more rows in total than the governor limit allows.

How do I fix System.LimitException: Too many query rows?

1. Filter queries to return only the rows you need and add LIMIT. 2. Process big sets in Batch Apex, which gets fresh limits per batch.

More Governor limits errors

SFDX Talk is unofficial documentation. It is not affiliated with, endorsed by, or sponsored by Salesforce, Inc. Message text varies slightly by release and context, so confirm against the official page before relying on it.