soql-optimization

Analyze Salesforce SOQL query plans to identify and optimize inefficient queries.

2|Updated Mar 18, 2026
One-click install
npx skills add https://github.com/bhanu91221/claude-sfdx-iq --skill soql-optimization
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: soql-optimization
Source: https://github.com/bhanu91221/claude-sfdx-iq/tree/main/skills/soql-optimization
Command: npx skills add https://github.com/bhanu91221/claude-sfdx-iq --skill soql-optimization

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Salesforce data access often suffers from inefficient SOQL queries that cause slow performance and governor-limit pressure. This skill helps you analyze and optimize queries by interpreting query plans, identifying selective filters, and guiding indexing decisions.

Core Features & Use Cases

  • Query Plan tool usage: analyze query plans from Developer Console or Tooling API to assess performance characteristics.
  • Reading and interpreting plan fields: cardinality, leadingOperationType, relativeCost, and sobjectCardinality to guide optimizations.
  • Applying best practices: enforce LIMIT usage, avoid leading wildcards, optimize relationship queries, and design appropriate indexing strategies for common filters.
  • Real-world scenarios: bulk data loads, complex joins across related objects, and incremental query tuning to stay within governor limits.

Quick Start

Open Developer Console, run a SOQL query with the Query Plan tool, and apply the recommended optimizations to improve performance.

Frequently Asked Questions about soql-optimization

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I optimize SOQL queries to avoid Salesforce governor limits?

Optimize SOQL queries by interpreting query plans to identify selective filters, applying LIMIT clauses, and avoiding leading wildcards. This reduces relativeCost and sobjectCardinality to prevent governor-limit exhaustion during Salesforce data access.

What does the Salesforce Query Plan tool tell me about SOQL performance?

The Salesforce Query Plan tool reveals the leadingOperationType, cardinality, relativeCost, and sobjectCardinality of your SOQL. Interpreting these plan fields guides indexing decisions and highlights inefficient filters causing bulk query bottlenecks.

How do I use query plan fields to improve SOQL selectivity?

Improve SOQL selectivity by analyzing query plan fields like cardinality and relativeCost. High relativeCost indicates non-selective filters; optimize them by designing appropriate indexing strategies for common filters to lower the leading operation cost.

Why does my SOQL query with a leading wildcard cause performance issues?

Leading wildcards cause performance issues because they bypass database indexes, forcing a full table scan. This increases the query plan's relativeCost and triggers governor-limit pressure during Salesforce data retrieval.

Can I optimize bulk SOQL queries for large Salesforce data loads?

Yes, you can optimize bulk SOQL queries for large Salesforce data loads by validating selective filters across object types and applying LIMIT usage. Interpreting the query plan ensures your incremental query tuning stays within governor limits.

When should I create custom indexes for SOQL queries in Salesforce?

Create custom indexes for SOQL queries when the query plan shows a high relativeCost and a TableScan as the leadingOperationType. Indexing common filters improves selectivity and is required to optimize complex joins across related objects.