platform-soql-query
SOQL query generation, optimization, and analysis with 100-point scoring. Use this skill when the user needs SOQL/SOSL authoring or optimization: natural-language-to-query generation, relationship queries, aggregates, query-plan analysis, and performance or safety improvements for Salesforce queries. TRIGGER when: user writes, optimizes, or debugs SOQL/SOSL queries, touches .soql files, or asks about relationship queries, aggregates, or query performance. DO NOT TRIGGER when: bulk data operation
Security Assessment
About platform-soql-query
The platform-soql-query skill is a Salesforce SOQL query expert for SOQL/SOSL authoring and optimization, including natural-language-to-query generation, relationship queries, aggregates, query-plan analysis, and performance or safety improvements, evaluated with a 100-point scoring guide. It triggers when a user writes, optimizes, or debugs SOQL/SOSL queries, touches .soql files, or asks about relationship queries, aggregates, or query performance. It explicitly does not own bulk data operations (which go to platform-data-manage), Apex DML logic (platform-apex-generate), or report and dashboard queries.
The skill gathers required context first — target objects, fields, filter criteria, sort/limit needs, intended use, and whether selectivity is already a concern — then follows a recommended workflow: generate the simplest correct query, choose the right query shape from a decision table (child-to-parent traversal, subquery, aggregate query, semi-join/anti-join, or SOSL), optimize for selectivity and safety, and validate the execution path if needed. High-signal rules include querying only required fields, never querying inside Apex loops, filtering in SOQL rather than post-filtering in Apex, using aggregates for counts, and evaluating wildcard usage since leading wildcards often defeat indexes. Output is reported in a fixed order (query purpose, final SOQL/SOSL, why the shape was chosen, optimization or security notes, and an execution suggestion), and results map to a score guide where 90+ is production-optimized and below 70 needs revision.
The skill ships an extensive reference and asset index for Salesforce developers: references such as soql-syntax-reference.md, query-optimization.md, anti-patterns.md, selector-patterns.md, field-coverage-rules.md, and cli-commands.md, plus .soql asset examples for basic, relationship, aggregate, and optimization patterns and .cls templates for bulkified queries and selector classes. A post-tool-validate.py script runs static SOQL validation and live query-plan analysis after .soql file edits. It defines clear cross-skill hand-offs — delegating execution and export to platform-data-manage, Apex embedding to platform-apex-generate, log-based debugging to platform-apex-logs-debug, and query-backed UI to experience-lwc-generate.
FAQ
When should I use platform-soql-query versus another platform skill?
Use it for SOQL/SOSL authoring and optimization, .soql files, relationship and aggregate queries, and selectivity analysis. Delegate elsewhere for bulk data operations (platform-data-manage), embedding query logic in broader Apex (platform-apex-generate), and log-based debugging (platform-apex-logs-debug).
What is the recommended workflow?
Generate the simplest correct query with only needed fields and clear WHERE criteria, choose the right query shape (traversal, subquery, aggregate, semi/anti-join, or SOSL), optimize for selectivity and safety, and validate the execution path if runtime verification is needed.
What does the 100-point score mean?
90+ is a production-optimized query, 80-89 is good with minor improvements possible, 70-79 is functional but has performance concerns, and below 70 needs revision before production use.
How are query performance and safety enforced?
By querying only required fields, avoiding queries inside Apex loops, filtering in SOQL instead of post-filtering in Apex, using aggregates for counts, evaluating wildcard usage (leading wildcards often defeat indexes), and accounting for security mode and field access when queries move into Apex.
Is there automated validation?
Yes. The scripts/post-tool-validate.py post-write hook runs static SOQL validation and live query plan analysis after .soql file edits. The bundle also includes reference files and .soql/.cls asset examples for common query patterns.
All Files
16 filesInstall platform-soql-query
Quick Setup:
- Copy the skill folder to
.claude/skills/ - Claude will automatically detect and use the skill
Repository
forcedotcom/sf-skills