limit-usage
Skill1 starsChanged 7 months agoMITView on GitHub
Static estimate of governor-limit consumption per public Apex method — count of SOQL queries, DML statements, callouts, queries-in-loops, async enqueues. Useful for spotting bulk-unsafe code before runtime.
In this repository53 other files it gives its agents.
- templates/CLAUDE.mdCLAUDE.md
- adrSkill
- agent-deploySkill
- agent-discoverSkill
- agent-eval-trendSkill
- agent-exchange-listSkill
- agent-specSkill
- agent-testSkill
- agent-vs-flow-vs-apexSkill
- before-vs-after-triggerSkill
- code-reviewSkill
- complexitySkill
- coverage-trendSkill
- dead-codeSkill
- dependency-graphSkill
- deploySkill
- destructive-changesSkill
- diff-deploySkill
- erdSkill
- field-impactSkill
- flaky-test-finderSkill
- flow-auditSkill
- flow-vs-apexSkill
- fls-auditSkill
- gateway-configSkill
- generate-docsSkill
- lwc-vs-reactSkill
- mcp-tool-vs-restSkill
- notifySkill
- onboardSkill
- org-diffSkill
- org-exploreSkill
- package-versionSkill
- pattern-packSkill
- perf-reviewSkill
- permset-auditSkill
- pr-prepareSkill
- queueable-vs-batchSkill
- quick-deploySkill
- react-initSkill
- release-notesSkill
- scratch-orgSkill
- security-scanSkill
- sequence-diagramSkill
- sf-initSkill
- sharing-reviewSkill
- slack-agentSkill
- soql-analyzerSkill
- test-coverageSkill
- test-dataSkill
- test-planSkill
- trust-evalSkill
- trust-layer-auditSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 3 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 55
If the loop body contains a SOQL or DML statement → finding LIMIT-LOOP-DML (error) / LIMIT-LOOP-SOQL (error)
- Distinctive: line 56
If the loop body calls a method that has SOQL/DML — note (recursive resolution is approximate.
- Distinctive: line 61
Look for a static Boolean guard pattern (PRJ-6 in project-patterns.md)
- Very specific: line 62
If absent → finding LIMIT-ASYNC-NO-GUARD (warning)
- Distinctive: line 112
Cross-class call resolution is approximate: When method A calls method B and B has SOQL, A's effective count includes B's.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
You are estimating governor-limit usage per Apex method. The estimates are static and conservative — they count operations textually without simulating runtime branches. The output points to methods worth bulk-load testing.
Read Project Config First
source "${CLAUDE_PLUGIN_ROOT}/hooks/lib/config.sh"
APEX_SRC="$(sf_config_get '.paths.apexSource' "$ENV")"
TEST_SUFFIX="$(sf_config_get '.naming.apex.testSuffix' "$ENV")"Limits Reference
| Limit | Sync | Async |
| SOQL queries | 100 | 200 |
| DML statements | 150 | 150 |
| Records retrieved | 50,000 | 50,000 |
| Heap | 6 MB | 12 MB |
| CPU time | 10,000 ms | 60,000 ms |
| Callouts | 100 | 100 |
| Future calls | 50 | 0 |
| Queueable enqueues | 50 | 1 |
Input
$ARGUMENTS:
- (empty) — analyze all production Apex
<ClassName>— analyze a single class--threshold-soql <n>— flag methods with > N SOQL statements (default 5)--threshold-dml <n>— flag methods with > N DML statements (default 5)--ci/--format json|sarif/--out <path>
Steps
1. Per-method counters
For each method (public/private/global/static), count occurrences of:
- SOQL:
\[\s*SELECTandDatabase\.query|Database\.getQueryLocator - DML: bare
insert|update|upsert|delete|mergekeywords +Database\.(insert|update|...) - Callouts:
\bnew Http\(\)\.send|HttpRequest - Future:
@futureannotation on the method itself - Queueable:
System\.enqueueJob - Email:
Messaging\.sendEmail - Platform Event publish:
EventBus\.publish
2. Detect SOQL/DML inside loops
For each loop construct (for, while, do):
- If the loop body contains a SOQL or DML statement → finding
LIMIT-LOOP-DML(error) /LIMIT-LOOP-SOQL(error) - If the loop body calls a method that has SOQL/DML — note (recursive resolution is approximate; flag as "possible")
3. Detect missing static guard on async
For Queueable / @future / Schedulable methods:
- Look for a static Boolean guard pattern (PRJ-6 in project-patterns.md)
- If absent → finding
LIMIT-ASYNC-NO-GUARD(warning)
4. Output
Default Markdown:
# Governor-Limit Usage: <project.name>
Apex files scanned: 47 (production)
Run at: 2026-04-28T13:45:00Z
## Per-method summary (top 10 by SOQL count)
| Class.Method | SOQL | DML | Callouts | Async | Notes |
|--------------|------|-----|----------|-------|-------|
| OrderService.persist | 4 | 3 | 0 | 0 | bulk-safe |
| ReportBuilder.run | 12 | 0 | 0 | 0 | ⚠️ many SOQL; consider single query |
| OrderApiClient.fetchAll | 1 | 0 | 1 | 0 | callout in sync method |
| ...
## Findings
### Critical
- `LIMIT-LOOP-DML` — `BatchSyncJob.processChunk` line 88 has DML inside a `for` loop (10 records → 10 DML statements; 200 records → governor limit hit)
- ...
### High
- `LIMIT-LOOP-SOQL` — `LegacyImporter.importBatch` line 42 has SOQL inside a `for` loop
- ...
### Medium
- `LIMIT-MANY-SOQL` — `ReportBuilder.run` issues 12 SOQL statements per call; consider a single query with sub-selects
- ...
### Warnings
- `LIMIT-ASYNC-NO-GUARD` — `OrderUpdateQueueable.execute` has no static Boolean guard (PRJ-6); duplicate enqueues from triggers will run multiple times
- ...CI: SARIF emission per finding.
5. Exit codes
- 0 — no error/warning findings
- 1 — any finding
- 2 — config error
Rules
- Static counts are conservative. A method with 5 SOQL statements may run only 1–2 at runtime depending on branches. Treat counts as upper bounds
- Loop detection is heuristic. Reasonable accuracy for
for/while/doblocks; not for recursion. Don't crash on edge cases — flag as "possible" - Cross-class call resolution is approximate. When method A calls method B and B has SOQL, A's effective count includes B's. Mark these as "transitive" in the per-method table
- Honor the async distinction. Queueable / Batch methods are async; their thresholds are higher. Detect via
Database.Stateful/Queueable/Schedulable/Database.Batchable/@futureand apply the async limit table
Consumers
@architectconsumes the per-method summary when planning the "Governor Limit Budget" section of a design/argo:code-reviewrolls findings into the High/Medium severity sections
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

