Loading
Ongoing maintenance for Salesforce HelpRead More

Improve SOQL Query Performance - Selectivity and Custom Indexes

Publish Date: Oct 14, 2026
Description

Custom indexes, when used improperly, can slow query results rather than improve them. It is best to create filter conditions that are selective so the Salesforce Force.com query optimizer scans only the rows necessary in the targeted objects. The Force.com query optimizer does not use an index to drive queries that contain non-selective filter conditions, even if the fields in those filter conditions already have indexes.

Before requesting a custom index from Salesforce Support, review the resources below to determine whether adding selective filters to your SOQL (Salesforce Object Query Language) query can resolve the performance issue without a custom index.

Resolution

This article explains how to improve SOQL query performance in Salesforce through query selectivity, which self-service steps to try first, and which details to include in a Salesforce Support case when you request a custom index.

Before Creating a Case with Salesforce Support

Review these self-service options before submitting a custom index request:

  • Analyze your SOQL query using the Query Plan Tool. The Query Plan Tool is available in the Developer Console. It shows the query plan for any SOQL query and helps you identify non-selective filter conditions. For more information, see the Query Plan Tool (How To and FAQ).
  • Add selective filters to improve performance. Selective filters reduce the number of rows the optimizer must scan. For guidance, see Make SOQL Query Selective and Improve Performance with Custom Indexes Using Selective SOQL Queries.
  • Use the Query and Search Optimization Cheat Sheet for a quick reference on selectivity rules: Query and Search Optimization Cheat Sheet (PDF).

Details to Include When Requesting a Custom Index

Include the following information in your Salesforce Support case. Each item is required for Support to evaluate and implement the index correctly:

  • Fields to be indexed — Specifies which fields to focus on and which to leave alone.
  • SOQL query with bind values — Provide the actual literal value in your query, not an Apex variable reference. Support cannot execute queries with Apex variable bindings.
  • Login access — Enables Support to replicate and understand the issue in your org.
  • Error messages and timestamps — Any error logs or timestamps help Support understand the urgency and pattern of the issue.
  • Steps to replicate the error — Ensures that Support follows the same path you took to reproduce the problem.
  • Evaluation of additional filters — Sometimes adding filters to your query without impacting functionality can resolve the issue without requiring a custom index. If additional filters are not possible, explain why so Support can explore other options.

How to Provide a SOQL Query with Bind Values

When you provide your SOQL query, include the actual bind value, not an Apex variable. The following two examples show the difference.

Correct: SELECT Id, Case_Number__c FROM Case WHERE Severity__c = 'Critical'. Support can run this query directly.

Incorrect: SELECT Id, Case_Number__c FROM Case WHERE Severity__c = :severityLevel. Support cannot execute Apex variable references.

Knowledge Article Number

000387172

 
Loading
Salesforce Help | Article