sf-soql

Generates, optimizes, and validates Salesforce SOQL and SOSL queries with selectivity and security analysis.

1|Updated May 7, 2026
One-click install
npx skills add https://github.com/amanpraaj/sf-skill-hub --skill sf-soql-amanpraaj
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: sf-soql
Source: https://github.com/amanpraaj/sf-skill-hub/tree/main/skills/salesforce/sf-soql
Command: npx skills add https://github.com/amanpraaj/sf-skill-hub --skill sf-soql-amanpraaj

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing efficient Salesforce queries requires deep knowledge of SOQL syntax, relationship traversal, index selectivity, and governor limits. This Skill converts natural-language requirements into correct, performant SOQL/SOSL and audits existing queries for anti-patterns that cause full table scans, limit exceptions, or field-access runtime errors. ## Core Features & Use Cases - Natural Language to SOQL: Generate queries with the right shape—subqueries, dot-notation traversal, aggregates, semi/anti-joins, or SOSL—based on the data need. - Query Optimization & Scoring: Evaluate selectivity, indexed-field usage, LIMIT clauses, and wildcard patterns against a 100-point scoring rubric, with optional live Query Plan analysis via the Salesforce CLI. - Security & Apex Safety: Guidance on WITH SECURITY_ENFORCED, WITH USER_MODE, stripInaccessible, and field-coverage rules so queried fields match what Apex code actually accesses. - Use Case: Ask for "Accounts with open Opportunities created this quarter" and receive a selective, governor-aware query plus an explanation of filter and relationship choices, ready to run via sf data query. ## Quick Start Ask the agent to generate or optimize a SOQL query, for example: "Write a selective SOQL query that finds all Contacts whose Accounts are in the Technology industry, created in the last 90 days."

Frequently Asked Questions about sf-soql

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

FAQPage Schema
How do I convert natural language into a SOQL query?▼

Describe the target object, fields, filters, and sort or limit needs in plain English, and the Skill generates the simplest correct SOQL. It selects the right shape—subquery, dot-notation traversal, aggregate, or semi-join—based on the relationship direction and data volume.

How do I fix a non-selective SOQL query error in Salesforce?▼

Add an indexed field such as Id, Name, OwnerId, CreatedDate, or RecordTypeId to the WHERE clause so the filter returns under 10% of records. Avoid leading wildcards, negative operators, null checks, and formula fields in filters, which force full table scans.

Can I run a SOQL query plan analysis from the Salesforce CLI?▼

Yes. Use sf data query with the --use-tooling-api and --plan flags, or call the REST explain endpoint via sf api request. The Skill's validation hook can also run live query plan analysis automatically when an org is connected.

Why does Apex throw 'SObject row was retrieved via SOQL without querying the requested field'?▼

This error occurs when code accesses a field that was not included in the SELECT clause, including parent relationship fields like Account.Name. The fix is to add every accessed field—direct, relationship, or dynamic—to the query before use.

When should I use SOSL instead of SOQL?▼

Use SOSL for text search across multiple objects or fields, such as finding a term in Accounts, Contacts, and Leads simultaneously. Use SOQL when querying a single object with structured filters, relationships, or aggregates.

What are the SOQL governor limits in Salesforce?▼

Synchronous transactions allow 100 SOQL queries and 50,000 retrieved records; asynchronous contexts allow 200 queries. Additional limits include 2,000 maximum OFFSET, 20 subqueries, and 5 levels of parent relationship traversal.