sf-soql-optimization

Identify and optimize inefficient SOQL queries in Salesforce Apex code.

13|2|Updated Mar 18, 2026
One-click install
npx skills add https://github.com/jiten-singh-shahi/salesforce-claude-code --skill sf-soql-optimization
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sf-soql-optimization
Source: https://github.com/jiten-singh-shahi/salesforce-claude-code/tree/main/.cursor/skills/sf-soql-optimization
Command: npx skills add https://github.com/jiten-singh-shahi/salesforce-claude-code --skill sf-soql-optimization

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

SOQL queries are often written without proper selectivity, leading to governor limit exceptions and slow performance. This skill guides you through identifying non-selective queries, analyzing query plans, and applying index strategies to improve efficiency.

Core Features & Use Cases

  • Query plan analysis and index guidance to improve selectivity and reduce heap usage.
  • Best practices for avoiding SOQL-in-loops, optimizing relationship queries, and handling large data volumes.
  • Use cases include apex triggers, batch jobs, and service classes that read or manipulate large data sets.

Quick Start

Analyze a sample Apex class to find non-selective SOQL and apply the recommended refactorings.

Frequently Asked Questions about sf-soql-optimization

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

FAQPage Schema
How do I fix SOQL query exceptions in Apex triggers?

To fix SOQL query exceptions, remove SOQL-in-loops and apply bulk-friendly patterns to process records efficiently. This prevents governor limit exceptions when handling large data volumes in Apex triggers.

How do I make SOQL queries selective for large data volumes?

Making SOQL queries selective requires analyzing query plans and using indexed fields as filters. Applying index strategies reduces heap usage and improves query speed for large data sets.

How do I analyze a Salesforce query plan to optimize SOQL?

Analyzing a Salesforce query plan involves identifying non-selective filters that cause slow performance. Applying query plan tool guidance helps you implement index strategies and optimize SOQL efficiency.

Can I optimize relationship queries in Apex service classes?

Yes, you can optimize relationship queries in Apex service classes by following bulk-friendly best practices. This ensures efficient data handling and prevents governor limit exceptions during large data processing.

Why does my SOQL query fail governor limits in batch jobs?

SOQL queries fail governor limits in batch jobs due to non-selective filters and SOQL-in-loops. Refactoring these queries with indexed fields and bulk-friendly patterns resolves the limit exceptions.