sf-debug

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

sf-debug: Salesforce Debug Log Analysis & Troubleshooting

sf-debug: Salesforce调试日志分析与排障

Expert debugging engineer specializing in Apex debug log analysis, governor limit detection, performance optimization, and root cause analysis. Parse logs, identify issues, and automatically suggest fixes.
专业调试工程师,专注于Apex调试日志分析、Governor Limit检测、性能优化和根因分析。可解析日志、识别问题并自动给出修复建议。

Core Responsibilities

核心职责

  1. Log Analysis: Parse and analyze Apex debug logs for issues
  2. Governor Limit Detection: Identify SOQL, DML, CPU, and heap limit concerns
  3. Performance Analysis: Find slow queries, expensive operations, and bottlenecks
  4. Stack Trace Interpretation: Parse exceptions and identify root causes
  5. Agentic Fix Suggestions: Automatically suggest code fixes based on issues found
  6. Query Plan Analysis: Analyze SOQL query performance and selectivity
  1. 日志分析:解析并分析Apex调试日志以定位问题
  2. Governor Limit检测:识别SOQL、DML、CPU和堆内存限制相关问题
  3. 性能分析:查找慢查询、高开销操作和性能瓶颈
  4. 堆栈跟踪解析:解析异常并识别根本原因
  5. 智能修复建议:根据发现的问题自动给出代码修复建议
  6. 查询计划分析:分析SOQL查询的性能和选择性

Workflow (5-Phase Pattern)

工作流程(五阶段模式)

Phase 1: Log Collection

阶段1:日志收集

Use AskUserQuestion to gather:
  • Debug context (deployment failure, test failure, runtime error, performance issue)
  • Target org alias
  • User/Transaction ID if known
  • Time range of issue
Then:
  1. List available logs:
    sf apex list log --target-org [alias]
  2. Fetch specific log or tail real-time
  3. Create TodoWrite tasks
使用AskUserQuestion收集以下信息:
  • 调试上下文(部署失败、测试失败、运行时错误、性能问题)
  • 目标组织别名
  • 已知的用户/事务ID
  • 问题发生的时间范围
后续操作
  1. 列出可用日志:
    sf apex list log --target-org [alias]
  2. 获取特定日志或实时追踪
  3. 创建TodoWrite任务

Phase 2: Log Retrieval

阶段2:日志获取

List Recent Logs:
bash
sf apex list log --target-org [alias] --json
Get Specific Log:
bash
sf apex get log --log-id 07Lxx0000000000 --target-org [alias]
Tail Logs Real-Time:
bash
sf apex tail log --target-org [alias] --color
Set Debug Level:
bash
sf apex log tail --debug-level FINE --target-org [alias]
列出近期日志
bash
sf apex list log --target-org [alias] --json
获取特定日志
bash
sf apex get log --log-id 07Lxx0000000000 --target-org [alias]
实时追踪日志
bash
sf apex tail log --target-org [alias] --color
设置调试级别
bash
sf apex log tail --debug-level FINE --target-org [alias]

Phase 3: Log Analysis

阶段3:日志分析

Parse the debug log and analyze:
┌─────────────────────────────────────────────────────────────────┐
│                    DEBUG LOG ANALYSIS                            │
├─────────────────────────────────────────────────────────────────┤
│                                                                  │
│  1. EXECUTION OVERVIEW                                           │
│     ├── Transaction type (trigger, flow, REST, batch)            │
│     ├── Total execution time                                     │
│     └── Entry point identification                               │
│                                                                  │
│  2. GOVERNOR LIMIT ANALYSIS                                      │
│     ├── SOQL Queries: X/100                                      │
│     ├── DML Statements: X/150                                    │
│     ├── DML Rows: X/10,000                                       │
│     ├── CPU Time: X ms /10,000 ms                                │
│     ├── Heap Size: X bytes /6,000,000                            │
│     └── Callouts: X/100                                          │
│                                                                  │
│  3. PERFORMANCE HOTSPOTS                                         │
│     ├── Slowest SOQL queries (execution time)                    │
│     ├── Non-selective queries (full table scan)                  │
│     ├── Expensive operations (loops, iterations)                 │
│     └── External callout timing                                  │
│                                                                  │
│  4. EXCEPTIONS & ERRORS                                          │
│     ├── Exception type                                           │
│     ├── Stack trace                                              │
│     ├── Line number                                              │
│     └── Root cause identification                                │
│                                                                  │
│  5. RECOMMENDATIONS                                              │
│     ├── Immediate fixes                                          │
│     ├── Optimization suggestions                                 │
│     └── Architecture improvements                                │
│                                                                  │
└─────────────────────────────────────────────────────────────────┘
解析调试日志并进行分析:
┌─────────────────────────────────────────────────────────────────┐
│                    调试日志分析                                  │
├─────────────────────────────────────────────────────────────────┤
│                                                                  │
│  1. 执行概览                                                   │
│     ├── 事务类型(触发器、流程、REST、批处理)                  │
│     ├── 总执行时间                                             │
│     └── 入口点识别                                             │
│                                                                  │
│  2. Governor Limit分析                                          │
│     ├── SOQL查询:X/100                                         │
│     ├── DML语句:X/150                                          │
│     ├── DML行数:X/10,000                                       │
│     ├── CPU时间:X ms /10,000 ms                                │
│     ├── 堆内存:X bytes /6,000,000                            │
│     └── 外部调用:X/100                                          │
│                                                                  │
│  3. 性能热点                                                   │
│     ├── 最慢的SOQL查询(执行时间)                              │
│     ├── 非选择性查询(全表扫描)                                │
│     ├── 高开销操作(循环、迭代)                                │
│     └── 外部调用耗时                                            │
│                                                                  │
│  4. 异常与错误                                                 │
│     ├── 异常类型                                               │
│     ├── 堆栈跟踪                                              │
│     ├── 行号                                                   │
│     └── 根本原因识别                                           │
│                                                                  │
│  5. 建议                                                       │
│     ├── 即时修复方案                                          │
│     ├── 优化建议                                               │
│     └── 架构改进方案                                           │
│                                                                  │
└─────────────────────────────────────────────────────────────────┘

Phase 4: Issue Identification & Fix Suggestions

阶段4:问题识别与修复建议

Governor Limit Analysis Decision Tree:
IssueDetection PatternFix Strategy
SOQL in Loop
SOQL_EXECUTE_BEGIN
inside
METHOD_ENTRY
repeated
Query before loop, use Map for lookups
DML in Loop
DML_BEGIN
inside
METHOD_ENTRY
repeated
Collect in List, single DML after loop
Non-Selective Query
Query plan
shows > 100,000 rows
Add indexed filter or LIMIT
CPU Limit
CPU_TIME
approaching 10000
Optimize algorithms, use async
Heap Limit
HEAP_ALLOCATE
approaching 6MB
Reduce collection sizes, use FOR loops
Callout Limit
CALLOUT_EXTERNAL_ENTRY
count > 90
Batch callouts, use Queueable
Auto-Fix Command:
Skill(skill="sf-apex", args="Fix [issue type] in [ClassName] at line [lineNumber]")
Governor Limit分析决策树
问题检测模式修复策略
循环内SOQL
SOQL_EXECUTE_BEGIN
METHOD_ENTRY
内重复出现
循环前查询,使用Map进行查找
循环内DML
DML_BEGIN
METHOD_ENTRY
内重复出现
收集到List中,循环后执行单次DML
非选择性查询
Query plan
显示超过100,000行
添加索引过滤条件或LIMIT
CPU限制
CPU_TIME
接近10000
优化算法,使用异步处理
堆内存限制
HEAP_ALLOCATE
接近6MB
减少集合大小,使用FOR循环
外部调用限制
CALLOUT_EXTERNAL_ENTRY
计数超过90
批量调用,使用Queueable
自动修复命令
Skill(skill="sf-apex", args="Fix [issue type] in [ClassName] at line [lineNumber]")

Phase 5: Fix Implementation

阶段5:修复实施

  1. Generate fix using sf-apex skill
  2. Deploy fix using sf-deploy skill
  3. Verify fix by re-running and checking logs
  4. Report results

  1. 使用sf-apex技能生成修复代码
  2. 使用sf-deploy技能部署修复
  3. 重新运行并检查日志以验证修复效果
  4. 报告结果

Best Practices (100-Point Scoring)

最佳实践(百分制评分)

CategoryPointsKey Rules
Root Cause25Correctly identify the actual cause, not symptoms
Fix Accuracy25Suggested fix addresses the root cause
Performance Impact20Fix improves performance, doesn't introduce new issues
Completeness15All related issues identified, not just the first one
Clarity15Explanation is clear and actionable
Scoring Thresholds:
⭐⭐⭐⭐⭐ 90-100 pts → Expert analysis with optimal fix
⭐⭐⭐⭐   80-89 pts  → Good analysis, effective fix
⭐⭐⭐    70-79 pts  → Acceptable analysis, partial fix
⭐⭐      60-69 pts  → Basic analysis, may miss issues
⭐        <60 pts   → Incomplete analysis

类别分值核心规则
根本原因25准确识别根本原因,而非表面症状
修复准确性25建议的修复方案针对根本原因
性能影响20修复提升性能,不引入新问题
完整性15识别所有相关问题,而非仅第一个问题
清晰度15解释清晰且可执行
评分阈值
⭐⭐⭐⭐⭐ 90-100分 → 专家级分析,最优修复方案
⭐⭐⭐⭐   80-89分  → 良好分析,有效修复方案
⭐⭐⭐    70-79分  → 合格分析,部分修复方案
⭐⭐      60-69分  → 基础分析,可能遗漏问题
⭐        <60分   → 不完整分析

Debug Log Anatomy

调试日志结构

Log Structure

日志格式

XX.X (XXXXX)|TIMESTAMP|EVENT_TYPE|[PARAMS]|DETAILS
XX.X (XXXXX)|时间戳|事件类型|[参数]|详情

Key Event Types

关键事件类型

EventMeaningImportant For
EXECUTION_STARTED
Transaction beginsContext identification
CODE_UNIT_STARTED
Method/trigger entryCall stack tracing
SOQL_EXECUTE_BEGIN
Query startsQuery analysis
SOQL_EXECUTE_END
Query endsQuery timing
DML_BEGIN
DML startsDML analysis
DML_END
DML endsDML timing
EXCEPTION_THROWN
Exception occursError detection
FATAL_ERROR
Transaction failsCritical issues
LIMIT_USAGE
Limit snapshotGovernor limits
HEAP_ALLOCATE
Heap allocationMemory issues
CPU_TIME
CPU time usedPerformance
CALLOUT_EXTERNAL_ENTRY
Callout startsExternal calls
事件含义适用场景
EXECUTION_STARTED
事务开始上下文识别
CODE_UNIT_STARTED
方法/触发器入口调用栈追踪
SOQL_EXECUTE_BEGIN
查询开始查询分析
SOQL_EXECUTE_END
查询结束查询耗时分析
DML_BEGIN
DML开始DML分析
DML_END
DML结束DML耗时分析
EXCEPTION_THROWN
发生异常错误检测
FATAL_ERROR
事务失败严重问题
LIMIT_USAGE
限制快照Governor Limits监控
HEAP_ALLOCATE
堆内存分配内存问题分析
CPU_TIME
已用CPU时间性能分析
CALLOUT_EXTERNAL_ENTRY
外部调用开始外部调用分析

Log Levels

日志级别

LevelShows
NONENothing
ERRORErrors only
WARNWarnings and errors
INFOGeneral info (default)
DEBUGDetailed debug info
FINEVery detailed
FINERMethod entry/exit
FINESTEverything

级别显示内容
NONE无内容
ERROR仅错误信息
WARN警告和错误信息
INFO常规信息(默认)
DEBUG详细调试信息
FINE非常详细的信息
FINER方法入口/出口
FINEST所有信息

Common Issues & Solutions

常见问题与解决方案

1. SOQL Query in Loop

1. 循环内SOQL查询

Detection:
|SOQL_EXECUTE_BEGIN|[line 45]
|SOQL_EXECUTE_END|[1 row]
... (repeats 50+ times)
Analysis Output:
🔴 CRITICAL: SOQL Query in Loop Detected
   Location: AccountService.cls, line 45
   Impact: 50 queries executed, approaching 100 limit
   Pattern: SELECT inside for loop

📝 RECOMMENDED FIX:
   Move query BEFORE loop, use Map for lookups:

   // Before (problematic)
   for (Account acc : accounts) {
       Contact c = [SELECT Id FROM Contact WHERE AccountId = :acc.Id LIMIT 1];
   }

   // After (bulkified)
   Map<Id, Contact> contactsByAccount = new Map<Id, Contact>();
   for (Contact c : [SELECT Id, AccountId FROM Contact WHERE AccountId IN :accountIds]) {
       contactsByAccount.put(c.AccountId, c);
   }
   for (Account acc : accounts) {
       Contact c = contactsByAccount.get(acc.Id);
   }
检测特征
|SOQL_EXECUTE_BEGIN|[line 45]
|SOQL_EXECUTE_END|[1 row]
... (重复50次以上)
分析输出
🔴 严重:检测到循环内SOQL查询
   位置:AccountService.cls,第45行
   影响:已执行50次查询,接近100次限制
   模式:FOR循环内包含SELECT语句

📝 推荐修复方案:
   将查询移至循环前,使用Map进行查找:

   // 修复前(存在问题)
   for (Account acc : accounts) {
       Contact c = [SELECT Id FROM Contact WHERE AccountId = :acc.Id LIMIT 1];
   }

   // 修复后(批量处理)
   Map<Id, Contact> contactsByAccount = new Map<Id, Contact>();
   for (Contact c : [SELECT Id, AccountId FROM Contact WHERE AccountId IN :accountIds]) {
       contactsByAccount.put(c.AccountId, c);
   }
   for (Account acc : accounts) {
       Contact c = contactsByAccount.get(acc.Id);
   }

2. Non-Selective Query

2. 非选择性查询

Detection:
|SOQL_EXECUTE_BEGIN|[line 23]|SELECT Id FROM Lead WHERE Status = 'Open'
|SOQL_EXECUTE_END|[250000 rows queried]
Analysis Output:
🟠 WARNING: Non-Selective Query Detected
   Location: LeadService.cls, line 23
   Rows Scanned: 250,000
   Filter Field: Status (not indexed)

📝 RECOMMENDED FIX:
   Option 1: Add indexed field to WHERE clause
   Option 2: Create custom index on Status field
   Option 3: Add LIMIT clause if not all records needed

   // Before
   List<Lead> leads = [SELECT Id FROM Lead WHERE Status = 'Open'];

   // After (with additional selective filter)
   List<Lead> leads = [SELECT Id FROM Lead
                       WHERE Status = 'Open'
                       AND CreatedDate = LAST_N_DAYS:30
                       LIMIT 10000];
检测特征
|SOQL_EXECUTE_BEGIN|[line 23]|SELECT Id FROM Lead WHERE Status = 'Open'
|SOQL_EXECUTE_END|[250000 rows queried]
分析输出
🟠 警告:检测到非选择性查询
   位置:LeadService.cls,第23行
   扫描行数:250,000
   过滤字段:Status(未建立索引)

📝 推荐修复方案:
   选项1:在WHERE子句中添加带索引的字段
   选项2:为Status字段创建自定义索引
   选项3:如果不需要所有记录,添加LIMIT子句

   // 修复前
   List<Lead> leads = [SELECT Id FROM Lead WHERE Status = 'Open'];

   // 修复后(添加额外选择性过滤)
   List<Lead> leads = [SELECT Id FROM Lead
                       WHERE Status = 'Open'
                       AND CreatedDate = LAST_N_DAYS:30
                       LIMIT 10000];

3. CPU Time Limit

3. CPU时间限制

Detection:
|LIMIT_USAGE_FOR_NS|CPU_TIME|9500|10000
Analysis Output:
🔴 CRITICAL: CPU Time Limit Approaching (95%)
   Used: 9,500 ms
   Limit: 10,000 ms (sync) / 60,000 ms (async)

📝 ANALYSIS:
   Top CPU consumers:
   1. StringUtils.formatAll() - 3,200 ms (line 89)
   2. CalculationService.compute() - 2,800 ms (line 156)
   3. ValidationHelper.validateAll() - 1,500 ms (line 45)

📝 RECOMMENDED FIX:
   1. Move heavy computation to @future or Queueable
   2. Optimize algorithms (O(n²) → O(n))
   3. Cache repeated calculations
   4. Use formula fields instead of Apex where possible
检测特征
|LIMIT_USAGE_FOR_NS|CPU_TIME|9500|10000
分析输出
🔴 严重:CPU时间限制接近阈值(95%)
   已使用:9,500 ms
   限制:10,000 ms(同步)/ 60,000 ms(异步)

📝 分析:
   CPU消耗Top3:
   1. StringUtils.formatAll() - 3,200 ms(第89行)
   2. CalculationService.compute() - 2,800 ms(第156行)
   3. ValidationHelper.validateAll() - 1,500 ms(第45行)

📝 推荐修复方案:
   1. 将重计算逻辑移至@future或Queueable
   2. 优化算法(从O(n²)优化为O(n))
   3. 缓存重复计算结果
   4. 尽可能使用公式字段替代Apex逻辑

4. Heap Size Limit

4. 堆内存限制

Detection:
|HEAP_ALLOCATE|[5800000]
|LIMIT_USAGE_FOR_NS|HEAP_SIZE|5800000|6000000
Analysis Output:
🔴 CRITICAL: Heap Size Limit Approaching (97%)
   Used: 5.8 MB
   Limit: 6 MB (sync) / 12 MB (async)

📝 ANALYSIS:
   Large allocations detected:
   1. Line 34: List<Account> - 2.1 MB (50,000 records)
   2. Line 78: Map<Id, String> - 1.8 MB
   3. Line 112: String concatenation - 1.2 MB

📝 RECOMMENDED FIX:
   1. Use SOQL FOR loops instead of querying all at once
   2. Process in batches of 200 records
   3. Use transient keyword for variables not needed in view state
   4. Clear collections when no longer needed

   // Before
   List<Account> allAccounts = [SELECT Id, Name FROM Account];

   // After (SOQL FOR loop - doesn't load all into heap)
   for (Account acc : [SELECT Id, Name FROM Account]) {
       // Process one at a time
   }
检测特征
|HEAP_ALLOCATE|[5800000]
|LIMIT_USAGE_FOR_NS|HEAP_SIZE|5800000|6000000
分析输出
🔴 严重:堆内存限制接近阈值(97%)
   已使用:5.8 MB
   限制:6 MB(同步)/ 12 MB(异步)

📝 分析:
   检测到大内存分配:
   1. 第34行:List<Account> - 2.1 MB(50,000条记录)
   2. 第78行:Map<Id, String> - 1.8 MB
   3. 第112行:字符串拼接 - 1.2 MB

📝 推荐修复方案:
   1. 使用SOQL FOR循环替代一次性查询所有记录
   2. 按200条记录批量处理
   3. 对视图状态中不需要的变量使用transient关键字
   4. 不再需要时清空集合

   // 修复前
   List<Account> allAccounts = [SELECT Id, Name FROM Account];

   // 修复后(SOQL FOR循环 - 不会将所有记录加载到堆内存)
   for (Account acc : [SELECT Id, Name FROM Account]) {
       // 逐个处理记录
   }

5. Exception Analysis

5. 异常分析

Detection:
|EXCEPTION_THROWN|[line 67]|System.NullPointerException: Attempt to de-reference a null object
|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object
Analysis Output:
🔴 EXCEPTION: System.NullPointerException
   Location: ContactService.cls, line 67
   Message: Attempt to de-reference a null object

📝 STACK TRACE ANALYSIS:
   ContactService.getContactDetails() - line 67
   └── AccountController.loadData() - line 34
       └── trigger AccountTrigger - line 5

📝 ROOT CAUSE:
   Variable 'contact' is null when accessing 'contact.Email'
   Likely scenario: Query returned no results

📝 RECOMMENDED FIX:
   // Before
   Contact contact = [SELECT Email FROM Contact WHERE AccountId = :accId LIMIT 1];
   String email = contact.Email;  // FAILS if no contact found

   // After (null-safe)
   List<Contact> contacts = [SELECT Email FROM Contact WHERE AccountId = :accId LIMIT 1];
   String email = contacts.isEmpty() ? null : contacts[0].Email;

   // Or using safe navigation (API 62.0+)
   Contact contact = [SELECT Email FROM Contact WHERE AccountId = :accId LIMIT 1];
   String email = contact?.Email;

检测特征
|EXCEPTION_THROWN|[line 67]|System.NullPointerException: Attempt to de-reference a null object
|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object
分析输出
🔴 异常:System.NullPointerException
   位置:ContactService.cls,第67行
   信息:尝试引用空对象

📝 堆栈跟踪分析:
   ContactService.getContactDetails() - 第67行
   └── AccountController.loadData() - 第34行
       └── trigger AccountTrigger - 第5行

📝 根本原因:
   访问'contact.Email'时变量'contact'为空
   可能场景:查询未返回结果

📝 推荐修复方案:
   // 修复前
   Contact contact = [SELECT Email FROM Contact WHERE AccountId = :accId LIMIT 1];
   String email = contact.Email;  // 无联系人时会失败

   // 修复后(空安全)
   List<Contact> contacts = [SELECT Email FROM Contact WHERE AccountId = :accId LIMIT 1];
   String email = contacts.isEmpty() ? null : contacts[0].Email;

   // 或使用安全导航(API 62.0+)
   Contact contact = [SELECT Email FROM Contact WHERE AccountId = :accId LIMIT 1];
   String email = contact?.Email;

CLI Command Reference

CLI命令参考

Log Management

日志管理

CommandPurpose
sf apex list log
List available logs
sf apex get log
Download specific log
sf apex tail log
Stream logs real-time
sf apex log delete
Delete logs
命令用途
sf apex list log
列出可用日志
sf apex get log
下载特定日志
sf apex tail log
实时流式查看日志
sf apex log delete
删除日志

Debug Level Control

调试级别控制

bash
undefined
bash
undefined

Create trace flag for user

为用户创建跟踪标记

sf data create record
--sobject TraceFlag
--values "TracedEntityId='005xx000000000' LogType='USER_DEBUG' DebugLevelId='7dlxx000000000' StartDate='2024-01-01T00:00:00' ExpirationDate='2024-01-02T00:00:00'"
--target-org my-sandbox
sf data create record
--sobject TraceFlag
--values "TracedEntityId='005xx000000000' LogType='USER_DEBUG' DebugLevelId='7dlxx000000000' StartDate='2024-01-01T00:00:00' ExpirationDate='2024-01-02T00:00:00'"
--target-org my-sandbox

Set default debug level

设置默认调试级别

sf config set org-api-version=62.0
undefined
sf config set org-api-version=62.0
undefined

Query Plan Analysis

查询计划分析

bash
undefined
bash
undefined

Use Developer Console or Tooling API

使用开发者控制台或Tooling API

sf data query
--query "SELECT Id FROM Account WHERE Name = 'Test'"
--target-org my-sandbox
--use-tooling-api
--plan

---
sf data query
--query "SELECT Id FROM Account WHERE Name = 'Test'"
--target-org my-sandbox
--use-tooling-api
--plan

---

Agentic Debug Loop

智能调试循环

When enabled, sf-debug will automatically:
┌─────────────────────────────────────────────────────────────────┐
│                    AGENTIC DEBUG LOOP                            │
├─────────────────────────────────────────────────────────────────┤
│                                                                  │
│  1. Fetch debug logs from the failing operation                  │
│  2. Parse logs and identify all issues                           │
│  3. Prioritize issues by severity:                               │
│     🔴 Critical: Limits exceeded, exceptions                     │
│     🟠 Warning: Approaching limits, slow queries                 │
│     🟡 Info: Optimization opportunities                          │
│  4. For each critical issue:                                     │
│     a. Read the source file at identified line                   │
│     b. Generate fix using sf-apex skill                          │
│     c. Deploy fix using sf-deploy skill                          │
│     d. Re-run operation and check new logs                       │
│  5. Report final status and remaining warnings                   │
│                                                                  │
└─────────────────────────────────────────────────────────────────┘

启用后,sf-debug将自动执行以下流程:
┌─────────────────────────────────────────────────────────────────┐
│                    智能调试循环                                  │
├─────────────────────────────────────────────────────────────────┤
│                                                                  │
│  1. 从失败操作中获取调试日志                                    │
│  2. 解析日志并识别所有问题                                       │
│  3. 按优先级排序问题:                                           │
│     🔴 严重:超出限制、异常                                     │
│     🟠 警告:接近限制、慢查询                                   │
│     🟡 信息:优化机会                                          │
│  4. 针对每个严重问题:                                           │
│     a. 读取指定行的源文件                                       │
│     b. 使用sf-apex技能生成修复代码                              │
│     c. 使用sf-deploy技能部署修复                                │
│     d. 重新运行操作并检查新日志                                 │
│  5. 报告最终状态和剩余警告                                       │
│                                                                  │
└─────────────────────────────────────────────────────────────────┘

Cross-Skill Integration

跨技能集成

SkillWhen to UseExample
sf-apexGenerate fixes for identified issues
Skill(skill="sf-apex", args="Fix NullPointerException in ContactService line 67")
sf-testingRun tests to reproduce issues
Skill(skill="sf-testing", args="Run AccountServiceTest to generate debug logs")
sf-deployDeploy fixes
Skill(skill="sf-deploy", args="Deploy ContactService.cls to sandbox")
sf-dataCreate test data for debugging
Skill(skill="sf-data", args="Create Account with specific conditions")

技能使用场景示例
sf-apex为识别的问题生成修复代码
Skill(skill="sf-apex", args="Fix NullPointerException in ContactService line 67")
sf-testing运行测试以重现问题
Skill(skill="sf-testing", args="Run AccountServiceTest to generate debug logs")
sf-deploy部署修复代码
Skill(skill="sf-deploy", args="Deploy ContactService.cls to sandbox")
sf-data创建调试用测试数据
Skill(skill="sf-data", args="Create Account with specific conditions")

Performance Benchmarks

性能基准

Healthy Limits

健康限制阈值

ResourceWarning ThresholdCritical Threshold
SOQL Queries80/100 (80%)95/100 (95%)
DML Statements120/150 (80%)145/150 (97%)
CPU Time8,000/10,000 ms9,500/10,000 ms
Heap Size4.8/6 MB5.7/6 MB
Callouts80/10095/100
资源警告阈值严重阈值
SOQL查询80/100(80%)95/100(95%)
DML语句120/150(80%)145/150(97%)
CPU时间8,000/10,000 ms9,500/10,000 ms
堆内存4.8/6 MB5.7/6 MB
外部调用80/10095/100

Query Performance

查询性能

CategoryAcceptableNeeds Optimization
Query Time< 100ms> 500ms
Rows Scanned< 10,000> 100,000
SelectivityIndexed filterFull table scan

类别可接受范围需要优化
查询时间< 100ms> 500ms
扫描行数< 10,000> 100,000
选择性使用索引过滤全表扫描

Documentation

文档

DocumentDescription
debug-log-reference.mdComplete debug log event reference
cli-commands.mdSF CLI debugging commands
benchmarking-guide.mdDan Appleman's technique, real-world benchmarks
log-analysis-tools.mdApex Log Analyzer, manual analysis patterns
文档描述
debug-log-reference.md完整的调试日志事件参考
cli-commands.mdSF CLI调试命令参考
benchmarking-guide.mdDan Appleman的技术、真实场景基准测试
log-analysis-tools.mdApex日志分析器、手动分析模式

Templates

模板

TemplateDescription
cpu-heap-optimization.clsCPU and heap optimization patterns
benchmarking-template.clsReady-to-run benchmark comparisons
soql-in-loop-fix.clsSOQL bulkification pattern
dml-in-loop-fix.clsDML bulkification pattern
null-pointer-fix.clsNull-safe patterns

模板描述
cpu-heap-optimization.clsCPU和堆内存优化模式
benchmarking-template.cls可直接运行的基准测试对比模板
soql-in-loop-fix.clsSOQL批量处理模式
dml-in-loop-fix.clsDML批量处理模式
null-pointer-fix.cls空安全模式

Credits

致谢

See CREDITS.md for acknowledgments of community resources that shaped this skill.

详见CREDITS.md,感谢为该技能提供支持的社区资源。

Dependencies

依赖项

Required: Target org with
sf
CLI authenticated Recommended: sf-apex (for auto-fix), sf-testing (for reproduction), sf-deploy (for deploying fixes)
Install:
/plugin install github:Jaganpro/sf-skills/sf-debug

必需条件:已通过
sf
CLI认证的目标组织 推荐:sf-apex(用于自动修复)、sf-testing(用于问题重现)、sf-deploy(用于部署修复)
安装:
/plugin install github:Jaganpro/sf-skills/sf-debug

License

许可证

MIT License. See LICENSE file. Copyright (c) 2024-2025 Jag Valaiyapathy
MIT许可证。详见LICENSE文件。 版权所有 (c) 2024-2025 Jag Valaiyapathy