forcedotcom/sf-skills / skills/dx-apexguru-scan
dx-apexguru-scan
VerifiedRun an ApexGuru performance scan on a Salesforce Apex project via the ApexGuru SFAP Scan API. Zips the project's Apex (any layout), submits it, polls to completion, decodes the base64 report, and presents performance antipattern violations (SOQL in loop, DML in loop, Schema.getGlobalDescribe(), SOQL without WHERE/LIMIT, unused SOQL fields) grouped by rule with severity, file:line, and suggested fixes — clearly attributed as 'Static only' or 'Production insights'. TRIGGER when the user says 'run ApexGuru', 'ApexGuru scan', 'check Apex performance', 'find governor-limit / performance antipatterns', 'SOQL in loop', 'scan my Apex for performance', or 'ApexGuru performance insights'. DO NOT TRIGGER for general static analysis or security scans (use dx-code-analyzer-run), for fixing code without scanning, or for onboarding an org to ApexGuru.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 20.4 KB |
| examples/README.md | markdown | 2.8 KB |
| examples/sample-decoded-summary.json | config | 4.3 KB |
| examples/sample-full-no-runtime-response.json | config | 27.6 KB |
| examples/sample-succeeded-response.json | config | 1.7 KB |
| references/api-reference.md | markdown | 2.5 KB |
| references/authentication.md | markdown | 7.1 KB |
| references/error-handling.md | markdown | 3.7 KB |
| references/violation-catalog.md | markdown | 2.1 KB |
| scripts/build-zip.shexecutable | script | 3.8 KB |
| scripts/decode-report.jsexecutable | script | 19.4 KB |
| scripts/resolve-token.shexecutable | script | 9.8 KB |
| scripts/run-scan.shexecutable | script | 6.5 KB |
| scripts/scan.shexecutable | script | 3.7 KB |
| scripts/validate-token.js | script | 5.5 KB |
scripts/scan.sh
View on GitHub#!/usr/bin/env bash
# One-shot ApexGuru performance scan: package → submit+poll → decode+present.
#
# This wrapper runs all three steps of the workflow in a single command so the
# scan cannot be left half-finished (a bare run-scan.sh already prints a
# violation count, which can read as "done" and tempt an early stop before the
# report is decoded). The FINAL stdout of this script is the ready-to-present
# markdown report from decode-report.js --present — print that to the user
# verbatim.
#
# Usage:
# bash scan.sh <project-root> [--out <report.md>]
# [--org <alias>] [--fast] [--raw <raw-out.json>]
#
# <project-root> folder that contains Apex somewhere beneath it (defaults to
# CWD if omitted or given as "."). build-zip.sh collects every
# .cls/.trigger under it, any layout.
# --out FILE also write the presented markdown to FILE (e.g. report.md).
# --org ALIAS forwarded to run-scan.sh (which sf org to derive the JWT from).
# --fast forwarded to run-scan.sh (skip LLM-heavy fix generation).
# --raw FILE keep the raw SUCCEEDED JSON at FILE (default: a temp file).
#
# The endpoint (prod/stage/dev) is chosen from the token's env by resolve-token.sh;
# customers on a prod org always hit api.salesforce.com.
#
# Progress for each step streams to STDERR; only the final presented markdown
# goes to STDOUT. On any step failure, the failing step's JSON error/hint is
# surfaced to stderr and the script exits non-zero.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT=""
OUT_FILE=""
RAW_OUT=""
ORG_ALIAS=""
FAST=""
# First non-flag arg is the project root.
while [ $# -gt 0 ]; do
case "$1" in
--out) OUT_FILE="${2:-}"; shift 2 ;;
--raw) RAW_OUT="${2:-}"; shift 2 ;;
--org) ORG_ALIAS="${2:-}"; shift 2 ;;
--fast) FAST="--fast"; shift ;;
*) [ -z "$PROJECT_ROOT" ] && PROJECT_ROOT="$1"; shift ;;
esac
done
[ -n "$PROJECT_ROOT" ] || PROJECT_ROOT="$(pwd)"
[ "$PROJECT_ROOT" = "." ] && PROJECT_ROOT="$(pwd)"
TS="$(date +%Y%m%d-%H%M%S)"
WORK_DIR="$(mktemp -d)"
ZIP_PATH="$WORK_DIR/apexguru-${TS}.zip"
[ -n "$RAW_OUT" ] || RAW_OUT="$WORK_DIR/apexguru-raw-${TS}.json"
cleanup() { [ -n "${WORK_DIR:-}" ] && rm -rf "$WORK_DIR" 2>/dev/null || true; }
trap cleanup EXIT
# --- Step 1: package the project's Apex into a zip ---
echo "[scan] Step 1/3: packaging $PROJECT_ROOT ..." >&2
ZIP_JSON="$(bash "$SCRIPT_DIR/build-zip.sh" "$PROJECT_ROOT" "$ZIP_PATH")" || {
echo "$ZIP_JSON" >&2
echo "[scan] packaging failed — see the error/hint above." >&2
exit 1
}
echo "[scan] packaged: $(echo "$ZIP_JSON" | jq -r '.humanSize // "?"') → $(echo "$ZIP_JSON" | jq -r '.zip')" >&2
# --- Step 2: submit + poll to completion ---
echo "[scan] Step 2/3: submitting and polling the scan ..." >&2
RUN_ARGS=("$ZIP_PATH" "$RAW_OUT")
[ -n "$ORG_ALIAS" ] && RUN_ARGS+=(--org "$ORG_ALIAS")
[ -n "$FAST" ] && RUN_ARGS+=("$FAST")
RUN_JSON="$(bash "$SCRIPT_DIR/run-scan.sh" "${RUN_ARGS[@]}")" || {
echo "$RUN_JSON" >&2
echo "[scan] scan failed — see the error/hint above." >&2
exit 1
}
echo "[scan] scan complete: $(echo "$RUN_JSON" | jq -r '.violationCount // "?"') violations" >&2
# --- Step 3: decode + present (this is the deliverable) ---
echo "[scan] Step 3/3: decoding and presenting the report ..." >&2
PRESENTED="$(node "$SCRIPT_DIR/decode-report.js" "$RAW_OUT" --present)" || {
echo "[scan] decoding failed against $RAW_OUT" >&2
exit 1
}
# Optionally persist the presented markdown (e.g. so it survives temp cleanup).
if [ -n "$OUT_FILE" ]; then
printf '%s\n' "$PRESENTED" > "$OUT_FILE"
echo "[scan] report also written to $OUT_FILE" >&2
fi
# FINAL stdout: the ready-to-present markdown. Print this to the user verbatim.
printf '%s\n' "$PRESENTED"
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |