Salesforce Dictionary — Free Salesforce GlossarySalesforce Dictionary

Query Locator

Development🔴 Advanced

Definition

In Salesforce Apex SOQL, a cursor returned by Database.getQueryLocator() that enables processing of up to 50 million records in batch Apex jobs, compared to the standard 50,000-record SOQL limit.

Real-World Example

When a senior developer at TerraForm Tech needs to streamline operations, they turn to Query Locator to solve a complex business requirement that cannot be addressed with declarative tools alone. They implement Query Locator with proper error handling, write 98% test coverage, and document the solution for future maintainers. The code passes security review on the first attempt.

Why Query Locator Matters

In Salesforce Apex SOQL, a Query Locator is a cursor returned by Database.getQueryLocator() that enables processing of up to 50 million records in batch Apex jobs, compared to the standard 50,000-record SOQL limit. The query locator is used as the start() method return value in batch Apex, giving the platform a way to chunk through huge datasets across multiple transactions.

Query locators are essential for batch Apex patterns that process large data volumes. Without query locators, you'd be stuck with the 50,000-record limit that applies to standard SOQL queries in Apex. With them, batch jobs can iterate over the entire org. Mature Apex code uses query locators appropriately in batch contexts, understanding that they work with the batch framework rather than standalone queries.

How Organizations Use Query Locator

  • Quantum LabsBuilt batch Apex jobs using query locators to process millions of records for data cleanup and migration.
  • CodeBridgeTrains developers on query locators as foundational for any batch Apex work.
  • TerraForm TechUses query locators in their nightly data processing jobs that iterate over their full customer database.

🧠 Test Your Knowledge

1. What is a Query Locator?

2. What's the record limit with query locators?

3. Where are query locators used?

See something that could be improved?

Suggest an Edit