The online Trailblazer Community becomes read-only Oct 30, 2026. Read More
| GOAL | Best Practice |
|---|---|
Allow indexed searches when SOQL queries with multiple WHERE filters can’t use indexes | Decompose the query. If you use two indexed fields joined by an OR in the WHERE clause, your search results can exceed the index threshold. Break the query into two queries and join the results. |
| Avoid querying on formula fields, which are computed in real time | If you have to query on formula fields, use formulas. Avoid filtering with formula fields that contain dynamic, non-deterministic references. See Standard and Custom Indexed Fields. |
| Use the most appropriate language, SOQL or SOSL, for a given search | See Using SOQL and SOSL. |
Execute queries with null values in a WHERE filter for picklists or foreign key fields | Use values such as NA to replace NULLS options. (See Using SOQL and SOSL.) |
| Design efficient custom query and search user interfaces | Use SOQL and SOSL where appropriate, keep queries focused, and minimize the amount of data being queried or searched. (See Using SOQL and SOSL.) |
| Build efficient SOQL and SOSL queries | Use filters and specific terms in your queries. For SOQL:
|
| Avoid timeouts on large SOQL queries | Tune the SOQL query, reducing query scope, and using selective filters. Consider using Bulk API 2.0 with Bulk API 2.0 Query. If you’ve used the previous suggestions and still get timeouts, consider adding a LIMIT clause (starting with 100,000 records) to your queries. If using batch Apex for your queries, use chaining to get sets of records (using LIMIT) or consider moving filter logic to the execute method. |