debugging-apex-logs
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesedebugging-apex-logs: Salesforce Debug Log Analysis & Troubleshooting
debugging-apex-logs: Salesforce调试日志分析与故障排查
Use this skill when the user needs root-cause analysis from debug logs: governor-limit diagnosis, stack-trace interpretation, slow-query investigation, heap / CPU pressure analysis, or a reproduction-to-fix loop based on log evidence.
当用户需要通过调试日志进行根因分析时使用本技能:包括Governor Limits诊断、堆栈跟踪解读、慢查询调查、堆/CPU压力分析,或基于日志证据的“复现-修复”循环。
When This Skill Owns the Task
本技能负责的任务场景
Use when the work involves:
debugging-apex-logs- files from Salesforce
.log - stack traces and exception analysis
- governor limits
- SOQL / DML / CPU / heap troubleshooting
- query-plan or performance evidence extracted from logs
Delegate elsewhere when the user is:
- running or repairing Apex tests → running-apex-tests
- generating or implementing the code fix → generating-apex
- debugging Agentforce session traces / parquet telemetry → observing-agentforce
当工作涉及以下内容时,使用:
debugging-apex-logs- Salesforce的.log文件
- 堆栈跟踪与异常分析
- Governor Limits
- SOQL / DML / CPU / 堆内存故障排查
- 从日志中提取查询计划或性能证据
当用户进行以下操作时,请转至其他技能:
- 运行或修复Apex测试 → running-apex-tests
- 生成或实现代码修复 → generating-apex
- 调试Agentforce会话跟踪/Parquet遥测数据 → observing-agentforce
Required Context to Gather First
需先收集的必要上下文信息
Ask for or infer:
- org alias
- failing transaction / user flow / test name
- approximate timestamp or transaction window
- user / record / request ID if known
- whether the goal is diagnosis only or diagnosis + fix loop
询问或推断:
- 组织别名(org alias)
- 失败的事务/用户流程/测试名称
- 大致时间戳或事务窗口
- 已知的用户/记录/请求ID
- 目标仅为诊断还是“诊断+修复”循环
Recommended Workflow
推荐工作流程
1. Retrieve logs
1. 获取日志
Use the commands in references/cli-commands.md to list, download, or stream logs for the target org.
使用references/cli-commands.md中的命令,列出、下载或流式传输目标组织的日志。
2. Analyze in this order
2. 按以下顺序分析
- entry point and transaction type
- exceptions / fatal errors
- governor limits
- repeated SOQL / DML patterns
- CPU / heap hotspots
- callout timing and external failures
- 入口点与事务类型
- 异常/致命错误
- Governor Limits
- 重复的SOQL / DML模式
- CPU / 堆内存热点
- 调用超时与外部故障
3. Classify severity
3. 分类严重程度
- Critical — runtime failure, hard limit, corruption risk
- Warning — near-limit, non-selective query, slow path
- Info — optimization opportunity or hygiene issue
- Critical(严重) — 运行时失败、硬限制触发、存在数据损坏风险
- Warning(警告) — 接近限制、非选择性查询、慢执行路径
- Info(信息) — 优化机会或代码规范问题
4. Recommend the smallest correct fix
4. 推荐最小化的正确修复方案
Prefer fixes that are:
- root-cause oriented
- bulk-safe
- testable
- easy to verify with a rerun
Expanded workflow: references/analysis-playbook.md
优先选择以下类型的修复:
- 针对根因的
- 支持批量处理的
- 可测试的
- 易于通过重新运行验证的
扩展工作流程:references/analysis-playbook.md
High-Signal Issue Patterns
高信号问题模式
| Issue | Primary signal | Default fix direction |
|---|---|---|
| SOQL in loop | repeating | query once, use maps / grouped collections |
| DML in loop | repeated | collect rows, bulk DML once |
| Non-selective query | high rows scanned / poor selectivity | add indexed filters, reduce scope |
| CPU pressure | CPU usage approaching sync limit | reduce algorithmic complexity, cache, async where valid |
| Heap pressure | heap usage approaching sync limit | stream with SOQL for-loops, reduce in-memory data |
| Null pointer / fatal error | | guard null assumptions, fix empty-query handling |
Expanded examples: references/common-issues.md
| 问题 | 主要信号 | 默认修复方向 |
|---|---|---|
| SOQL循环调用 | 重复调用路径中出现重复的 | 一次性查询,使用映射/分组集合 |
| DML循环调用 | 出现重复的 | 收集行数据,批量执行DML |
| 非选择性查询 | 扫描行数多/选择性差 | 添加索引过滤条件,缩小查询范围 |
| CPU压力 | CPU使用率接近同步模式限制 | 降低算法复杂度,使用缓存,合理使用异步处理 |
| 堆内存压力 | 堆内存使用率接近同步模式限制 | 使用SOQL循环流式处理,减少内存中存储的数据 |
| 空指针/致命错误 | 出现 | 增加空值判断,修复空查询的处理逻辑 |
扩展示例:references/common-issues.md
Output Format
输出格式
When finishing analysis, report in this order:
- What failed
- Where it failed (class / method / line / transaction stage)
- Why it failed (root cause, not just symptom)
- How severe it is
- Recommended fix
- Verification step
Suggested shape:
text
Issue: <summary>
Location: <class / line / transaction>
Root cause: <explanation>
Severity: Critical | Warning | Info
Fix: <specific action>
Verify: <test or rerun step>完成分析后,按以下顺序报告:
- 故障内容
- 故障位置(类/方法/行/事务阶段)
- 故障原因(根因,而非仅症状)
- 严重程度
- 推荐修复方案
- 验证步骤
建议格式:
text
问题: <摘要>
位置: <类 / 行 / 事务>
根因: <说明>
严重程度: Critical | Warning | Info
修复方案: <具体操作>
验证: <测试或重新运行步骤>Rules / Constraints
规则/约束
| Rule | Rationale |
|---|---|
| Always base fix recommendations on log evidence | Avoid speculative diagnosis — root cause must be traceable in the log |
| Report all six output fields for every issue found | Ensures actionable, complete findings for each problem |
| Classify every finding as Critical, Warning, or Info | Helps the user prioritize which issues to address first |
Delegate code generation to | This skill diagnoses; it does not rewrite Apex code |
Delegate test execution to | This skill does not run or repair test classes |
Never assume limits are safe without reading | Limits may be consumed by earlier operations not visible in the failure point |
| 规则 | 理由 |
|---|---|
| 修复建议必须始终基于日志证据 | 避免推测性诊断 — 根因必须可在日志中追溯 |
| 每个发现的问题都需报告全部六个输出字段 | 确保每个问题的结果可执行且完整 |
| 每个发现都需归类为Critical、Warning或Info | 帮助用户优先处理问题 |
代码生成任务转至 | 本技能仅负责诊断,不重写Apex代码 |
测试执行任务转至 | 本技能不运行或修复测试类 |
未读取 | 限制可能被故障点之前的操作消耗,而这些操作在故障点不可见 |
Gotchas
常见陷阱
| Pitfall | Resolution |
|---|---|
| Log truncated at 2 MB | Reduce debug levels (e.g., |
| Same issue appears as both SOQL and CPU problem | Fix SOQL-in-loop first — it typically drives the CPU spike as a secondary effect |
| No logs appear after trace flag is set | Verify the trace flag |
| Async context changes limit values | CPU limit is 60,000 ms async vs 10,000 ms sync — check transaction type before flagging limits |
| Stack trace points to framework line, not user code | Walk up the call stack past trigger handlers to find the originating user code |
| 陷阱 | 解决方法 |
|---|---|
| 日志被截断至2 MB | 降低调试级别(例如 |
| 同一问题同时表现为SOQL和CPU问题 | 优先修复SOQL循环调用 — 这通常是CPU飙升的次要原因 |
| 设置跟踪标志后无日志生成 | 验证跟踪标志的 |
| 异步上下文会改变限制值 | CPU限制在异步模式下为60,000毫秒,同步模式下为10,000毫秒 — 标记限制问题前需检查事务类型 |
| 堆栈跟踪指向框架代码行,而非用户代码 | 沿着调用栈向上追溯,跳过触发器处理程序,找到原始用户代码 |
Cross-Skill Integration
跨技能集成
| Need | Delegate to | Reason |
|---|---|---|
| Implement Apex fix | generating-apex | code change generation / review |
| Reproduce via tests | running-apex-tests | test execution and coverage loop |
| Deploy fix | deploying-metadata | deployment orchestration |
| Create debugging data | handling-sf-data | targeted seed / repro data |
| 需求 | 转至技能 | 原因 |
|---|---|---|
| 实现Apex修复 | generating-apex | 代码变更生成/审核 |
| 通过测试复现问题 | running-apex-tests | 测试执行与覆盖循环 |
| 部署修复方案 | deploying-metadata | 部署编排 |
| 创建调试数据 | handling-sf-data | 针对性的种子/复现数据 |
Reference File Index
参考文件索引
| File | When to read |
|---|---|
| Start here — expanded step-by-step workflow for any debugging session |
| Quick lookup for SOQL in loop, DML in loop, CPU/heap pressure, null pointer patterns |
| SF CLI commands for retrieving, streaming, and managing debug logs |
| Full event type catalog, log levels, and governor limit reference values |
| Tool guide: Apex Log Analyzer, Developer Console, CLI grep patterns |
| Performance benchmarking techniques, benchmark data, and anti-patterns |
| 100-point scoring rubric for evaluating analysis quality |
| Copy-paste Anonymous Apex template for running performance benchmarks |
| Apex patterns for reducing CPU time and heap allocation |
| Before/after example for resolving DML-in-loop violations |
| Before/after example for resolving SOQL-in-loop violations |
| Patterns for guarding against null pointer exceptions |
| 文件 | 阅读场景 |
|---|---|
| 入门必读 — 适用于任何调试会话的扩展分步工作流程 |
| 快速查找SOQL循环调用、DML循环调用、CPU/堆内存压力、空指针等模式 |
| 用于检索、流式传输和管理调试日志的SF CLI命令 |
| 完整的事件类型目录、日志级别和Governor Limits参考值 |
| 工具指南:Apex Log Analyzer、开发者控制台、CLI grep模式 |
| 性能基准测试技术、基准数据和反模式 |
| 用于评估分析质量的百分制评分标准 |
| 可复制粘贴的匿名Apex模板,用于运行性能基准测试 |
| 用于减少CPU时间和堆内存分配的Apex模式 |
| 解决DML循环调用问题的前后示例 |
| 解决SOQL循环调用问题的前后示例 |
| 防范空指针异常的模式 |
Score Guide
评分指南
| Score | Meaning |
|---|---|
| 90+ | Expert analysis with strong fix guidance |
| 80–89 | Good analysis with minor gaps |
| 70–79 | Acceptable but may miss secondary issues |
| 60–69 | Partial diagnosis only |
| < 60 | Incomplete analysis |
| 分数 | 含义 |
|---|---|
| 90+ | 专家级分析,修复指导清晰有力 |
| 80–89 | 良好分析,存在微小漏洞 |
| 70–79 | 合格,但可能遗漏次要问题 |
| 60–69 | 仅完成部分诊断 |
| < 60 | 分析不完整 |