Loading

Improve SOQL Query Performance - Selectivity and Custom Indexes

Publiceringsdatum: May 7, 2026
Beskrivning

Custom Indexes and Query Selectivity

Custom indexes, when used improperly, can actually 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 query can resolve the performance issue without a custom index.

Lösning

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 & 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 & Search Optimization Cheat Sheet for a quick reference on selectivity rules: Query & 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.

    When providing your SOQL query, include the actual bind value, not an Apex variable. For example:
    • Correct: SELECT Id, Case_Number__c FROM Case WHERE Severity__c = 'Critical' — Support can run this directly.
    • Incorrect: SELECT Id, Case_Number__c FROM Case WHERE Severity__c = :severityLevel — Support cannot execute Apex variable references.
  • 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.
Ytterligare resurser
Knowledge-artikelnummer

000387172

 
Laddar
Salesforce Help | Article