Token导航 LogoToken导航TokenDH.com
开发只读github未标认证来源可访问许可证需确认审计通过

trigger-refactor-pipeline触发重构管道

Agent Skill

trigger-refactor-pipeline 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

8,836

周安装

354

GitHub Stars

212

下载量

2,860
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:trigger-refactor-pipeline(触发重构管道)
来源仓库:https://github.com/forcedotcom/afv-library
仓库路径:skills/trigger-refactor-pipeline
安装命令:
npx skills add https://github.com/forcedotcom/afv-library --skill trigger-refactor-pipeline
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/forcedotcom/afv-library --skill trigger-refactor-pipeline

简介

trigger-refactor-pipeline 用于处理 GitHub 仓库、Issue、Pull Request 等协作信息。

  • 适合围绕代码变更、仓库状态和协作事项进行整理与分析。
  • 可通过 npx 命令从指定仓库安装并使用该技能。
  • 使用前需确认 token 权限和操作边界,避免越权访问或修改。
  • 适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

When to Use This Skill

Use this skill when you need to:

  • Modernize legacy triggers with DML/SOQL operations inside loops
  • Refactor triggers that lack clear separation of concerns
  • Implement bulk-safe patterns in existing trigger code
  • Generate comprehensive test coverage for refactored triggers

Prerequisites

Before starting, ensure you have:

  1. Salesforce CLI installed and authenticated to your target org
  2. Python 3.9 or higher installed
  3. The baseline trigger deployed (see Setup section)

Setup

Deploy the baseline anti-pattern trigger to analyze and refactor:

// ❌ Anti-pattern: all logic stuffed into the trigger, with DML/SOQL in loops.
trigger OpportunityTrigger on Opportunity (before insert, before update, after update) {
    // BEFORE INSERT: validate Closed Won w/ low Amount
    if (Trigger.isBefore && Trigger.isInsert) {
        for (Opportunity o : Trigger.new) {
            if (o.StageName == 'Closed Won' && (o.Amount == null || o.Amount < 1000)) {
                o.addError('Closed Won opportunities must have Amount ≥ 1000.');
            }
        }
    }

    // BEFORE UPDATE: if Stage changed, overwrite Description
    if (Trigger.isBefore && Trigger.isUpdate) {
        for (Opportunity o : Trigger.new) {
            Opportunity oldO = Trigger.oldMap.get(o.Id);
            if (o.StageName != oldO.StageName) {
                o.Description = 'Stage changed from ' + oldO.StageName + ' to ' + o.StageName;
            }
        }
    }

    // AFTER UPDATE: when Stage becomes Closed Won, create a follow-up Task
    if (Trigger.isAfter && Trigger.isUpdate) {
        for (Opportunity o : Trigger.new) {
            Opportunity oldO = Trigger.oldMap.get(o.Id);
            if (o.StageName == 'Closed Won' && oldO.StageName != 'Closed Won') {
                Task t = new Task(
                    WhatId     = o.Id,
                    OwnerId    = o.OwnerId,
                    Subject    = 'Send thank-you',
                    Status     = 'Not Started',
                    Priority   = 'Normal',
                    ActivityDate = Date.today()
                );
                insert t; // ❌ DML in a loop
            }
        }
    }
}

Deploy this to your org:

sf project deploy start --source-dir force-app/main/default/triggers

Step 1: Analyze the Trigger

Run the analysis script to identify anti-patterns and generate a report:

python scripts/analyze_trigger.py OpportunityTrigger

The script will output:

  • DML in loops - Line numbers where DML operations occur inside iteration
  • SOQL in loops - Line numbers where SOQL queries occur inside iteration
  • Missing bulkification - Areas where collection-based processing is needed
  • Complexity score - Overall trigger complexity rating (1-10)
  • Recommended approach - Suggested handler pattern based on trigger contexts

Review the analysis report before proceeding to refactoring.

Step 2: Review Handler Patterns

Consult the handler patterns reference to understand:

  • Single-responsibility handlers - One handler class per trigger context
  • Unified handler approach - Single handler with context methods
  • Bulk collection strategies - How to aggregate DML/SOQL outside loops
  • Best practices - Error handling, test boundaries, deployment order

Choose the pattern that best fits your trigger's complexity and team conventions.

Step 3: Refactor the Trigger

Create the handler class using the appropriate pattern from the reference guide:

  1. Extract logic into handler methods with descriptive names
  2. Implement bulk-safe collections for DML operations
  3. Add proper error handling using try-catch or Database methods
  4. Update the trigger to delegate only, passing Trigger context variables
  5. Preserve behavior - ensure the refactored code produces identical results

The trigger should be reduced to simple delegation:

trigger OpportunityTrigger on Opportunity (before insert, before update, after update) {
    OpportunityTriggerHandler handler = new OpportunityTriggerHandler();

    if (Trigger.isBefore && Trigger.isInsert) {
        handler.beforeInsert(Trigger.new);
    }

    if (Trigger.isBefore && Trigger.isUpdate) {
        handler.beforeUpdate(Trigger.new, Trigger.oldMap);
    }

    if (Trigger.isAfter && Trigger.isUpdate) {
        handler.afterUpdate(Trigger.new, Trigger.oldMap);
    }
}

Step 4: Generate Tests

Use the test template from assets/test_template.apex to scaffold your test class:

  1. Copy the template and rename for your handler
  2. Implement setup methods to create test data
  3. Write unit tests covering each handler method:

- Positive cases with valid data - Negative cases with invalid data - Boundary conditions

  1. Add bulk tests with 200+ records to verify bulkification
  2. Test mixed scenarios where only some records qualify for logic

Required test coverage:

  • Each handler method must have at least 2 test methods (positive + negative)
  • At least one bulk test with 200+ records
  • Overall code coverage must be 100%

Step 5: Deploy and Validate

Deploy the refactored trigger, handler, and tests:

# Deploy all components
sf project deploy start --source-dir force-app/main/default

# Run tests
sf apex test run --class-names OpportunityTriggerHandlerTest --result-format human --code-coverage

# Verify no regressions
sf apex test run --test-level RunLocalTests --result-format human

Validation checklist:

  • All new tests pass with 100% coverage
  • No new governor limit warnings in debug logs
  • Existing functionality remains unchanged
  • Deployment to production planned with rollback strategy

Troubleshooting

Issue: Tests fail with "System.LimitException: Too many DML statements"

  • Solution: Ensure handler methods collect DML operations and execute outside loops

Issue: Code coverage below 100%

  • Solution: Add negative test cases and verify all conditional branches are tested

Issue: Behavior differs from original trigger

  • Solution: Review Trigger context variables (new, old, oldMap) are passed correctly to handler

Next Steps

After successful refactoring:

  1. Document the new handler pattern in your team's wiki
  2. Update code review checklist to enforce handler patterns for new triggers
  3. Identify other legacy triggers for refactoring using this skill
  4. Consider implementing a trigger framework if managing many triggers

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

38.04%
按下载量换算1,088

Claude

29.78%
按下载量换算852

Cursor

20.58%
按下载量换算589

Gemini CLI

8.98%
按下载量换算257

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

只读

该 Skill 主要提供规则、说明或参考内容,本身偏只读;真正读写文件、联网或执行命令仍取决于宿主 Agent 的任务。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills