Loading

SQLException 'User requested cancel of current operation'

Date de publication: Jun 15, 2026
Description

A SQLException error occurs when running a Batch Apex job: "First error: SQLException [java.sql.SQLException: ORA-01013: user requested cancel of current operation] thrown but connection was canceled." The batch job is then aborted. This error indicates that a SOQL query within the batch exceeded Salesforce's 2-minute database query timeout and was automatically cancelled. While this error commonly appears in Batch Apex, it can occur in any context where a SOQL query runs longer than 2 minutes, including queries affected by index issues or large data volumes.

Résolution

Root Cause — Query Selectivity

The ORA-01013 error occurs when a SOQL query is unselective — meaning it cannot use a database index and must perform a full table scan instead. Full table scans take time proportional to the number of records in the object. The same query may succeed in a sandbox (where total record count including soft-deleted records is lower) but time out in production (where record count is higher). A query is selective when at least one WHERE clause filter returns fewer than 10% of the total records (up to 333,000 records) AND the filter is based on an indexed field.

What Makes a Query Selective?

A query is selective when it meets both criteria:

  1. At least one WHERE clause filter returns fewer than 10% of total records (up to 333,000 records).
  2. The filter is applied to an indexed field.

Standard indexed fields include: lookup fields, master-detail relationship fields, unique fields, external ID fields, and audit fields (such as CreatedDate and LastModifiedDate). Salesforce Support can create custom indexes on specific fields upon request.

How to Diagnose Query Selectivity

Use the Query plan tool in the Developer Console to evaluate whether your SOQL query is index-driven. A "TableScan" operation in the query plan indicates the query is unselective and will scale poorly with data volume. An index-based plan indicates the query is selective.

Resolution Options

  1. Add a selective WHERE clause filter: Add a filter on an indexed field (such as CreatedDate or a lookup field) to make the query index-driven and reduce execution time.
  2. Request a custom index: Open a case with Salesforce Support to request a custom index on the field(s) most frequently used in your WHERE clause.
  3. Refactor the Batch Apex start() method: Update the QueryLocator in the start() method to use a more selective filter that reduces the result set and ensures index use.



Numéro d’article de la base de connaissances

000385898

 
Chargement
Salesforce Help | Article