Loading...
Loading...
Advanced SOQL skill with natural language to query generation, query optimization, relationship traversal, aggregate functions, and performance analysis. Build efficient queries that respect governor limits and security requirements.
npx skill4agent add jaganpro/sf-skills sf-soql| Request | Generated SOQL |
|---|---|
| "Get all active accounts with their contacts" | |
| "Find contacts created this month" | |
| "Count opportunities by stage" | |
| "Get accounts with revenue over 1M sorted by name" | |
# Test query
sf data query --query "SELECT Id, Name FROM Account LIMIT 10" --target-org my-org --json
# Analyze query plan
sf data query --query "..." --target-org my-org --use-tooling-api --plan| Category | Points | Key Rules |
|---|---|---|
| Selectivity | 25 | Indexed fields in WHERE, selective filters |
| Performance | 25 | Appropriate LIMIT, minimal fields, no unnecessary joins |
| Security | 20 | WITH SECURITY_ENFORCED or stripInaccessible |
| Correctness | 15 | Proper syntax, valid field references |
| Readability | 15 | Formatted, meaningful aliases, comments |
-- Enforce FLS (throws exception on inaccessible fields)
SELECT Id, Name, Phone FROM Account WITH SECURITY_ENFORCED
-- Respect sharing rules
SELECT Id, Name FROM Account WITH USER_MODESee references/query-optimization.md forin Apex,stripInaccessible, governor limits, SOQL FOR loops, indexing strategy, and selectivity rules.SYSTEM_MODE
| Limit | Synchronous | Asynchronous |
|---|---|---|
| Total SOQL Queries | 100 | 200 |
| Records Retrieved | 50,000 | 50,000 |
Anti-pattern: Never query inside a loop. UsewithMap<Id, SObject>instead.WHERE Id IN :idSet
See references/soql-syntax-reference.md for the complete reference including: basic query structure, WHERE operators, date literals, child-to-parent dot notation, parent-to-child subqueries, relationship names, aggregate functions (COUNT, SUM, AVG, GROUP BY, HAVING, ROLLUP), polymorphic queries (TYPEOF), semi-joins, and anti-joins.
SELECT Contact.Account.Name FROM CaseSELECT Id, (SELECT Id FROM Contacts) FROM Account__rCustom_Object__r.NameSELECT Industry, COUNT(Id) FROM Account GROUP BY Industry HAVING COUNT(Id) > 10See references/query-optimization.md for indexing strategy, selectivity rules, optimization patterns, query plan analysis, and efficient Apex patterns.
LIKE 'Acme%'LIKE '%corp'LIMITsf data query --plan| Request | SOQL |
|---|---|
| "Get me all accounts" | |
| "Find contacts without email" | |
| "Top 10 opportunities by amount" | |
| "Contacts with @gmail emails" | |
| "Opportunities closing this quarter" | |
| "Total revenue by industry" | |
# Basic query (JSON output)
sf data query --query "SELECT Id, Name FROM Account LIMIT 10" --target-org my-org --json
# CSV output to file
sf data query --query "SELECT Id, Name FROM Account" --target-org my-org --result-format csv --output-file accounts.csv
# Bulk export (> 2,000 records)
sf data export bulk --query "SELECT Id, Name FROM Account" --target-org my-org --output-file accounts.csv
# SOSL search
sf data search --query "FIND {Acme} IN ALL FIELDS RETURNING Account(Id, Name), Contact(Id, Name)" --target-org my-org| Skill | When to Use | Example |
|---|---|---|
| sf-apex | Embed queries in Apex | Use the sf-apex skill: "Create service with SOQL query for accounts" |
| sf-data | Execute queries against org | Use the sf-data skill: "Query active accounts from production" |
| sf-debug | Analyze query performance | Use the sf-debug skill: "Analyze slow query in debug logs" |
| sf-lwc | Generate wire queries | Use the sf-lwc skill: "Create component with wired account query" |
| Document | Description |
|---|---|
| SOQL Syntax Reference | Complete syntax, operators, dates, relationships, aggregates, advanced features |
| Query Optimization | Indexing, selectivity, patterns, query plan, governor limits, security |
| Document | Description |
|---|---|
| soql-reference.md | Complete SOQL syntax reference |
| cli-commands.md | SF CLI query commands |
| anti-patterns.md | Common mistakes and how to avoid them |
| selector-patterns.md | Query abstraction patterns (vanilla Apex) |
| field-coverage-rules.md | Ensure queries include all accessed fields |
| Template | Description |
|---|---|
| basic-queries.soql | Basic SOQL syntax examples |
| aggregate-queries.soql | COUNT, SUM, GROUP BY patterns |
| relationship-queries.soql | Parent-child traversals |
| optimization-patterns.soql | Selectivity and indexing |
| selector-class.cls | Selector class template |
| bulkified-query-pattern.cls | Map-based bulk lookups |
sf