Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
clientell-ai avatar

Sf Soql

  • 43 installs
  • 12 repo stars
  • Updated July 14, 2026
  • clientell-ai/salesforce-skills

Sf-soql is an agent skill that provides a comprehensive SOQL and SOSL reference with date literals and example queries for Salesforce objects.

About

Sf-soql is a Salesforce SOQL and SOSL reference skill for solo builders shipping SaaS or internal tools on Clientell-style Salesforce stacks. It catalogs date literals from single-day anchors through week, month, and quarter windows, each with clear start/end behavior and example queries against common CRM objects. Use it when you are wiring Apex, Flow-adjacent logic, agent-driven data pulls, or analytics exports and need literal syntax without guessing calendar boundaries. The skill reduces integration bugs from off-by-one date filters and inconsistent activity versus created date fields. It does not replace Salesforce security review or bulk API governance; it accelerates correct query authoring during backend and integration work. Intermediate familiarity with Salesforce objects helps; beginners can still lean on the literal tables as a checklist while pairing with org-specific field metadata.

  • Comprehensive SOQL/SOSL reference oriented to real SELECT examples.
  • Standard date literals table (YESTERDAY, TODAY, TOMORROW) with boundary semantics.
  • Week, month, and quarter literal families (THIS_WEEK, LAST_MONTH, THIS_QUARTER, etc.).
  • Copy-pasteable filter patterns on Opportunity, Lead, Case, Task, and Event objects.
  • Supports aggregate queries such as SUM(Amount) with date literal WHERE clauses.

Sf Soql by the numbers

  • 43 all-time installs (skills.sh)
  • Ranked #3,266 of 4,347 Backend & APIs skills by installs in the Skillselion catalog
  • Security screen: LOW risk (skills.sh audit)
  • Data as of Jul 28, 2026 (Skillselion catalog sync)
npx skills add https://github.com/clientell-ai/salesforce-skills --skill sf-soql

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs43
repo stars12
Security audit3 / 3 scanners passed
Last updatedJuly 14, 2026
Repositoryclientell-ai/salesforce-skills

What it does

Write correct Salesforce SOQL and SOSL queries with date literals, filters, and relationship patterns while building CRM-backed features.

Who is it for?

Best when you're adding Salesforce CRM reads, reports, or agent queries during feature integration.

Skip if: Skip if you need only non-Salesforce SQL or and already centralize queries in a governed internal style guide.

When should I use this skill?

Authoring or reviewing Salesforce SOQL/SOSL queries that use date literals or standard object filters.

What you get

After using the reference, you produce valid SOQL with correct date literals and object-specific WHERE clauses ready for Apex, APIs, or agent-generated data jobs.

  • Validated SOQL/SOSL query strings
  • Date-literal filters aligned to Salesforce calendar rules

By the numbers

  • Standard, week, month, and quarter date literal tables with example SELECT statements

Files

SKILL.mdMarkdownGitHub ↗

SOQL Query Builder & Optimizer

You are a Salesforce SOQL specialist. Build optimized, secure queries.

Security First

  • ALWAYS use WITH USER_MODE to enforce CRUD/FLS
  • NEVER use string concatenation for dynamic SOQL — use bind variables
  • Use Database.query() only when dynamic queries are truly needed
// GOOD
List<Account> accounts = [
    SELECT Id, Name, Industry
    FROM Account
    WHERE Industry = :industryFilter
    WITH USER_MODE
    LIMIT 200
];

// BAD — injection risk
String query = 'SELECT Id FROM Account WHERE Name = \'' + userInput + '\'';

Query Patterns

Parent-to-Child (Subquery)

SELECT Id, Name,
    (SELECT Id, FirstName, LastName FROM Contacts)
FROM Account
WHERE Industry = 'Technology'
WITH USER_MODE

Child-to-Parent (Dot Notation)

SELECT Id, FirstName, Account.Name, Account.Industry
FROM Contact
WHERE Account.Industry = 'Technology'
WITH USER_MODE

Aggregate Queries

SELECT Industry, COUNT(Id) cnt, SUM(AnnualRevenue) totalRevenue
FROM Account
WHERE Industry != null
WITH USER_MODE
GROUP BY Industry
HAVING COUNT(Id) > 5
ORDER BY COUNT(Id) DESC

Polymorphic (TYPEOF)

SELECT Id, Subject,
    TYPEOF What
        WHEN Account THEN Name, Industry
        WHEN Opportunity THEN Name, StageName, Amount
    END
FROM Task
WITH USER_MODE

Semi-Joins and Anti-Joins

-- Semi-join: Accounts WITH contacts
SELECT Id, Name FROM Account
WHERE Id IN (SELECT AccountId FROM Contact)
WITH USER_MODE

-- Anti-join: Accounts WITHOUT opportunities
SELECT Id, Name FROM Account
WHERE Id NOT IN (SELECT AccountId FROM Opportunity)
WITH USER_MODE

SOSL (Search Language)

Use SOSL for full-text search across multiple objects:

FIND {SearchTerm} IN ALL FIELDS
RETURNING Account(Id, Name WHERE Industry = 'Tech'),
          Contact(Id, FirstName, LastName)
LIMIT 20
  • Use SOSL when: searching text across objects, fuzzy matching, partial words
  • Use SOQL when: exact matches, relationship queries, aggregates, DML-related queries
  • Governor limit: 20 SOSL queries per transaction

Date Literals

LiteralMeaning
TODAY, YESTERDAY, TOMORROWCalendar day
THIS_WEEK, LAST_WEEK, NEXT_WEEKSun-Sat week
THIS_MONTH, LAST_MONTH, NEXT_MONTHCalendar month
THIS_QUARTER, LAST_QUARTERCalendar quarter
THIS_YEAR, LAST_YEAR, NEXT_YEARCalendar year
LAST_N_DAYS:nPast n days (includes today)
NEXT_N_DAYS:nNext n days (includes today)
LAST_90_DAYSPast 90 days
THIS_FISCAL_QUARTER, THIS_FISCAL_YEARFiscal periods
N_DAYS_AGO:nExactly n days ago

FIELDS() Functions

SELECT FIELDS(ALL) FROM Account LIMIT 200    -- All fields (LIMIT required)
SELECT FIELDS(STANDARD) FROM Account          -- Standard fields only
SELECT FIELDS(CUSTOM) FROM Account            -- Custom fields only

Dynamic SOQL

String query = 'SELECT Id, Name FROM Account WHERE Industry = :industry';
List<Account> results = Database.query(query, AccessLevel.USER_MODE);
  • Always use AccessLevel.USER_MODE with Database.query()
  • Use :bindVariable syntax — never string concatenation
  • For truly dynamic field names: String.escapeSingleQuotes()

Utility Functions

  • toLabel(PicklistField) — returns translated picklist label
  • FORMAT(NumberField) — locale-formatted number/date
  • convertCurrency(Amount) — converts to user's currency (multi-currency orgs)

Record Locking

SELECT Id, Name FROM Account WHERE Id = :accountId FOR UPDATE

Pessimistic lock — blocks other transactions from updating until commit/rollback.

ALL ROWS (Including Deleted)

SELECT Id, Name FROM Account WHERE IsDeleted = true ALL ROWS

Returns soft-deleted records (retained 15 days in Recycle Bin).

SOQL For Loops

for (List<Account> batch : [SELECT Id, Name FROM Account]) {
    // Processes 200 records per iteration automatically
    // Uses minimal heap — ideal for large datasets
}

Geolocation Queries

SELECT Id, Name, DISTANCE(Location__c, GEOLOCATION(37.7749, -122.4194), 'mi') dist
FROM Store__c
WHERE DISTANCE(Location__c, GEOLOCATION(37.7749, -122.4194), 'mi') < 50
ORDER BY DISTANCE(Location__c, GEOLOCATION(37.7749, -122.4194), 'mi')

WITH SECURITY_ENFORCED vs WITH USER_MODE

FeatureSECURITY_ENFORCEDUSER_MODE
FLS enforcementSELECT/FROM onlySELECT/FROM/WHERE/subqueries
On violationThrows exceptionSilently strips inaccessible fields
Restriction rulesNot supportedSupported
RecommendationLegacy — migrate awayPreferred

Optimization Rules

Selective Filters (use indexed fields)

  • Id, Name, OwnerId, CreatedDate, SystemModstamp
  • RecordTypeId, Lookup fields, External ID fields
  • Custom fields marked as External ID or with custom index

Anti-Patterns to Detect

1. Query in loop — move query before the loop, use Map/Set 2. Non-selective filter — filter on indexed fields first 3. SELECT \ equivalent — never select all fields, only what's needed 4. Missing LIMIT — add LIMIT for queries that could return large datasets 5. Negative filters — `!=` and `NOT IN` are non-selective 6. Leading wildcard — `LIKE '%term'` cannot use indexes 7. Missing WHERE clause* — always filter unless deliberately loading all

Query Plan Analysis

sf data query -q "EXPLAIN SELECT Id FROM Account WHERE Name = 'Test'" --target-org myOrg

Limits

  • 100 SOQL queries per synchronous transaction
  • 200 SOQL queries per asynchronous transaction
  • 50,000 rows returned per transaction
  • 2,000 rows in a subquery
  • 20 relationship queries per parent query

Gotchas

  • FIELDS(ALL) REQUIRES LIMIT 200 — fails without it
  • COUNT() counts all rows including nulls; COUNT(fieldName) counts non-null only
  • FOR UPDATE locks the ENTIRE row — other transactions wait or timeout
  • SOSL has its own governor limit: 20 queries/transaction (separate from SOQL's 100)
  • Date literals include the boundary day — LAST_N_DAYS:7 includes today
  • TYPEOF only works on polymorphic fields (Task.What, Event.Who, etc.)
  • Subquery result limit is 2,000 rows — not 50,000
  • FIELDS(ALL) is not supported in Apex — only REST API and Developer Console
  • Database.query() does not support FIELDS() — use explicit field lists
  • ALL ROWS cannot be used with FOR UPDATE

Workflow

1. Understand the data requirements 2. Check object relationships and field types 3. Build query with proper filters, security, and limits 4. Test with: sf data query -q "YOUR_QUERY" --target-org myOrg 5. Optimize based on results and explain plan

References

  • SOQL/SOSL Reference — date literals, SOSL syntax, FIELDS(), geolocation, dynamic SOQL, aggregates, FOR UPDATE, bind patterns, query plans
  • Governor Limits — SOQL query limits per transaction

Related skills

How it compares

Reference procedural skill for SOQL literals, not a live MCP connector to your org.

FAQ

Who is sf-soql for?

Sf-soql is for developers and agent users implementing Salesforce integrations who need authoritative SOQL date literal and query patterns at coding time.

When should I use sf-soql?

Use sf-soql in Build integrations whenever you filter Leads, Opportunities, Cases, Tasks, or Events by CreatedDate, CloseDate, or ActivityDate using THIS_MONTH, LAST_WEEK, or related literals.

Is sf-soql safe to install?

The skill is documentation-style query reference; confirm vendor trust via the Security Audits panel on this page before installing third-party Salesforce skills in your agent.

Backend & APIsintegrationsbackend

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.