Instruction file imported from beyond-the-cloud-dev/soql-lib (
.cursor/rules/soql-lib.mdc). Copyright stays with the author.
description: SOQL Lib conventions for Apex code that queries Salesforce records globs: /*.cls,/*.trigger alwaysApply: false
SOQL Lib
This project reads Salesforce data through SOQL Lib (SOQL.cls).
- Build queries with SOQL Lib. Use
SOQL_<Object>.query()when that selector exists, otherwiseSOQL.of(<Object>.SObjectType)(orSOQL.of('RecordType')for RecordType). If the project already usesSOQLCache, use it for cached records. Don't write[SELECT ...],Database.query()orDatabase.queryWithBinds(). When SOQL Lib can't express a query, write it as a static query wrapped inSOQLEvaluator.of([...]). - Build Sets and Maps from a query with result methods (
toIds,toIdsOf,toValuesOf,toMap,toIdMapBy,toAggregatedMap,toAggregatedIdMapBy) instead of looping overtoList(). Thesoql-lib-query-builderskill lists their limits. - In unit tests, return query results with
SOQL.mock(...)instead of inserting records. UseSOQLCache.mock(...)andSOQLEvaluator.mock(...)for those classes. OnlytoQueryLocator(),toCursor()andtoPaginationCursor()ignore mocks. SOQL.of(...)runs in user mode, with CRUD, FLS and sharing enforced, so don't add.userMode()to it. Selectors usually callsystemMode()andwithoutSharing()in their constructor, so call.userMode()on a selector wherever the running user's access must apply..systemMode()alone skips CRUD and FLS but keeps the caller's sharing. This replaces generic advice such asWITH USER_MODEorWITH SECURITY_ENFORCED.- Values passed to
SOQL.FilterandSOQL.HavingFiltercomparators are bound, so don't concatenate or escape them. Some inputs go into the query text as written: multi-select picklist values,.asDateLiteral()values, data categories, field and object names given as strings, sort directions and raw conditions (whereAre(String),FilterGroup.add(String),have(String)). Validate user input before passing it to any of these. - Before writing code, load the matching skill (from
.claude/skills/):soql-lib-query-builderfor queries,soql-lib-selectorfor selector classes,soql-lib-testingfor tests that mock queries.
These rules don't apply to SOQL Lib's own source: SOQL.cls, SOQLCache.cls, CacheManager.cls, SOQLEvaluator.cls and their test classes.
