🎯

sf-debug

🎯Skill

from jaganpro/claude-code-sfskills

VibeIndex|
What it does

Parses Salesforce debug logs to detect performance bottlenecks, governor limit violations, and automatically suggest code optimizations and fixes.

πŸ“¦

Part of

jaganpro/claude-code-sfskills(20 items)

sf-debug

Installation

Install ScriptRun install script
curl -sSL https://raw.githubusercontent.com/Jaganpro/sf-skills/main/tools/install.sh | bash
git cloneClone repository
git clone https://github.com/Jaganpro/sf-skills
PythonRun Python server
python tools/installer.py --cli opencode --all # OpenCode
PythonRun Python server
python tools/installer.py --cli codex --all # Codex (OpenAI)
PythonRun Python server
python tools/installer.py --cli gemini --all # Gemini (Google)

+ 17 more commands

πŸ“– Extracted from docs: jaganpro/claude-code-sfskills
1Installs
-
AddedFeb 4, 2026

Skill Details

SKILL.md

>

Overview

# sf-debug: Salesforce Debug Log Analysis & Troubleshooting

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.

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

Workflow (5-Phase Pattern)

Phase 1: Log Collection

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

Phase 2: Log Retrieval

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]

```

Phase 3: Log Analysis

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 β”‚

β”‚ β”‚

β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

```

Phase 4: Issue Identification & Fix Suggestions

Governor Limit Analysis Decision Tree:

| Issue | Detection Pattern | Fix 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]")

```

Phase 5: Fix Implementation

  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

---

Best Practices (100-Point Scoring)

| Category | Points | Key Rules |

|----------|--------|-----------|

| Root Cause | 25 | Correctly identify the actual cause, not symptoms |

| Fix Accuracy | 25 | Suggested fix addresses the root cause |

| Performance Impact | 20 | Fix improves performance, doesn't introduce new issues |

| Completeness | 15 | All related issues identified, not just the first one |

| Clarity | 15 | Explanation 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

```

---

Debug Log Anatomy

Log Structure

```

XX.X (XXXXX)|TIMESTAMP|EVENT_TYPE|[PARAMS]|DETAILS

```

Key Event Types

| Event | Meaning | Important For |

|-------|---------|---------------|

| EXECUTION_STARTED | Transaction begins | Context identification |

| CODE_UNIT_STARTED | Method/trigger entry | Call stack tracing |

| SOQL_EXECUTE_BEGIN | Query starts | Query analysis |

| SOQL_EXECUTE_END | Query ends | Query timing |

| DML_BEGIN | DML starts | DML analysis |

| DML_END | DML ends | DML timing |

| EXCEPTION_THROWN | Exception occurs | Error detection |

| FATAL_ERROR | Transaction fails | Critical issues |

| LIMIT_USAGE | Limit snapshot | Governor limits |

| HEAP_ALLOCATE | Heap allocation | Memory issues |

| CPU_TIME | CPU time used | Performance |

| CALLOUT_EXTERNAL_ENTRY | Callout starts | External calls |

Log Levels

| Level | Shows |

|-------|-------|

| NONE | Nothing |

| ERROR | Errors only |

| WARN | Warnings and errors |

| INFO | General info (default) |

| DEBUG | Detailed debug info |

| FINE | Very detailed |

| FINER | Method entry/exit |

| FINEST | Everything |

---

Common Issues & Solutions

1. SOQL Query in Loop

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 contactsByAccount = new Map();

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

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 leads = [SELECT Id FROM Lead WHERE Status = 'Open'];

// After (with additional selective filter)

List leads = [SELECT Id FROM Lead

WHERE Status = 'Open'

AND CreatedDate = LAST_N_DAYS:30

LIMIT 10000];

```

3. CPU Time Limit

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

```

4. Heap Size Limit

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 - 2.1 MB (50,000 records)

2. Line 78: Map - 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 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

}

```

5. Exception Analysis

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 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;

```

---

CLI Command Reference

Log Management

| Command | Purpose |

|---------|---------|

| 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 |

Debug Level Control

```bash

# 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

# Set default debug level

sf config set org-api-version=62.0

```

Query Plan Analysis

```bash

# Use Developer Console or Tooling API

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 β”‚

β”‚ β”‚

β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

```

---

Cross-Skill Integration

| Skill | When to Use | Example |

|-------|-------------|---------|

| sf-apex | Generate fixes for identified issues | Skill(skill="sf-apex", args="Fix NullPointerException in ContactService line 67") |

| sf-testing | Run tests to reproduce issues | Skill(skill="sf-testing", args="Run AccountServiceTest to generate debug logs") |

| sf-deploy | Deploy fixes | Skill(skill="sf-deploy", args="Deploy ContactService.cls to sandbox") |

| sf-data | Create test data for debugging | Skill(skill="sf-data", args="Create Account with specific conditions") |

---

Performance Benchmarks

Healthy Limits

| Resource | Warning Threshold | Critical Threshold |

|----------|-------------------|-------------------|

| SOQL Queries | 80/100 (80%) | 95/100 (95%) |

| DML Statements | 120/150 (80%) | 145/150 (97%) |

| CPU Time | 8,000/10,000 ms | 9,500/10,000 ms |

| Heap Size | 4.8/6 MB | 5.7/6 MB |

| Callouts | 80/100 | 95/100 |

Query Performance

| Category | Acceptable | Needs Optimization |

|----------|------------|-------------------|

| Query Time | < 100ms | > 500ms |

| Rows Scanned | < 10,000 | > 100,000 |

| Selectivity | Indexed filter | Full table scan |

---

Documentation

| Document | Description |

|----------|-------------|

| [debug-log-reference.md](docs/debug-log-reference.md) | Complete debug log event reference |

| [cli-commands.md](docs/cli-commands.md) | SF CLI debugging commands |

| [benchmarking-guide.md](docs/benchmarking-guide.md) | Dan Appleman's technique, real-world benchmarks |

| [log-analysis-tools.md](docs/log-analysis-tools.md) | Apex Log Analyzer, manual analysis patterns |

Templates

| Template | Description |

|----------|-------------|

| [cpu-heap-optimization.cls](templates/cpu-heap-optimization.cls) | CPU and heap optimization patterns |

| [benchmarking-template.cls](templates/benchmarking-template.cls) | Ready-to-run benchmark comparisons |

| [soql-in-loop-fix.cls](templates/soql-in-loop-fix.cls) | SOQL bulkification pattern |

| [dml-in-loop-fix.cls](templates/dml-in-loop-fix.cls) | DML bulkification pattern |

| [null-pointer-fix.cls](templates/null-pointer-fix.cls) | Null-safe patterns |

---

Credits

See [CREDITS.md](CREDITS.md) for acknowledgments of community resources that shaped this skill.

---

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

---

License

MIT License. See [LICENSE](LICENSE) file.

Copyright (c) 2024-2025 Jag Valaiyapathy

More from this repository10

🎯
sf-testing🎯Skill

Executes Salesforce Apex tests with comprehensive coverage analysis, automatic failure detection, and intelligent test-fixing capabilities.

🎯
sf-lwc🎯Skill

Generates production-ready Lightning Web Components for Salesforce using PICKLES architecture, ensuring robust, accessible, and performant UI development with comprehensive testing and integration.

🎯
sf-ai-agentforce-testing🎯Skill

Validates and tests AI agent interactions and workflows within Salesforce using automated testing frameworks and scenarios.

🎯
sf-flow🎯Skill

Generates and validates Salesforce flows with comprehensive 110-point scoring, ensuring Winter '26 best practices and high-performance flow design.

🎯
sf-diagram-nanobananapro🎯Skill

Generates Salesforce ERD diagrams, LWC mockups, and architecture visuals using Gemini and Nano Banana Pro AI technology.

🎯
sf-data🎯Skill

Executes Salesforce data operations with expert SOQL querying, bulk data management, and test data generation across Salesforce orgs.

🎯
sf-ai-agentforce-legacy🎯Skill

Generates legacy Agentforce agents using Agent Script syntax with 100-point scoring for maintaining existing agent patterns.

🎯
util-youtube-analyzer🎯Skill

Analyzes YouTube video details, extracts metadata, and provides insights about video content, views, and engagement metrics.

🎯
sf-permissions🎯Skill

Analyzes Salesforce Permission Sets, revealing access hierarchies, detecting specific permissions, and auditing user access across objects, fields, and Apex classes.

🎯
sf-connected-apps🎯Skill

Generates and configures Salesforce Connected Apps and External Client Apps with comprehensive OAuth setup, security validation, and 120-point scoring mechanism.