sf-flow

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

sf-flow: Salesforce Flow Creation and Validation

sf-flow: Salesforce Flow 创建与验证

Expert Salesforce Flow Builder with deep knowledge of best practices, bulkification, and Winter '26 (API 65.0) metadata. Create production-ready, performant, secure, and maintainable flows.
资深Salesforce Flow构建专家,精通最佳实践、批量处理以及Winter '26(API 65.0)元数据。可创建适合生产环境、高性能、安全且易于维护的Flow。

Quick Reference: Validation Script

快速参考:验证脚本

bash
python3 ~/.claude/plugins/marketplaces/sf-skills/sf-flow/hooks/scripts/validate_flow.py <flow-file.xml>
Scoring: 110 points across 6 categories. Minimum 88 (80%) for deployment.

bash
python3 ~/.claude/plugins/marketplaces/sf-skills/sf-flow/hooks/scripts/validate_flow.py <flow-file.xml>
评分体系:分为6个类别,总分110分。部署最低要求为88分(80%)。

Core Responsibilities

核心职责

  1. Flow Generation: Create well-structured Flow metadata XML from requirements
  2. Strict Validation: Enforce best practices with comprehensive checks and scoring
  3. Safe Deployment: Integrate with sf-deploy skill for two-step validation and deployment
  4. Testing Guidance: Provide type-specific testing checklists and verification steps

  1. Flow生成:根据需求创建结构清晰的Flow元数据XML
  2. 严格验证:通过全面检查和评分体系执行最佳实践
  3. 安全部署:与sf-deploy技能集成,实现两步式验证与部署
  4. 测试指导:提供针对不同类型的测试清单和验证步骤

CRITICAL: Orchestration Order

重要提示:编排顺序

sf-metadata → sf-flow → sf-deploy → sf-data (you are here: sf-flow)
Flow references custom object/fields? Create with sf-metadata FIRST. Deploy objects BEFORE flows. See
references/orchestration.md
for extended patterns including Agentforce.

sf-metadata → sf-flow → sf-deploy → sf-data(当前位置:sf-flow)
Flow引用了自定义对象/字段?请先使用sf-metadata创建它们。部署Flow前需先部署对象。如需包含Agentforce的扩展模式,请参阅
references/orchestration.md

Key Insights

关键要点

InsightDetails
Before vs After SaveBefore-Save: same-record updates (no DML), validation. After-Save: related records, emails, callouts
Test with 251Batch boundary at 200. Test 251+ records for governor limits, N+1 patterns, bulk safety
$Record contextSingle-record, NOT a collection. Platform handles batching. Never loop over $Record
Transform vs LoopTransform: data mapping/shaping (30-50% faster). Loop: per-record decisions, counters, varying logic. See
references/transform-vs-loop-guide.md

要点详情
保存前 vs 保存后保存前:同记录更新(无需DML)、验证。保存后:关联记录操作、发送邮件、外部调用
用251条数据测试批量处理阈值为200条。测试251条以上数据,检查 governor 限制、N+1查询模式、批量处理安全性
$Record 上下文单记录上下文,而非集合。平台会处理批量操作。切勿遍历$Record
转换 vs 循环转换:数据映射/格式调整(速度快30-50%)。循环:单记录决策、计数、可变逻辑。请参阅
references/transform-vs-loop-guide.md

Workflow Design (5-Phase Pattern)

工作流设计(5阶段模式)

Phase 1: Requirements Gathering

阶段1:需求收集

Before building, evaluate alternatives: See
references/flow-best-practices.md
Section 1 — sometimes a Formula Field, Validation Rule, or Roll-Up Summary is the better choice.
Ask the user to gather: flow type, primary purpose, trigger object/conditions, target org alias.
Then: Check existing flows (
Glob: **/*.flow-meta.xml
), offer reusable subflows from
references/subflow-library.md
, reference
references/governance-checklist.md
for complex automation.
构建前,请评估替代方案:参阅
references/flow-best-practices.md
第1节——有时公式字段、验证规则或汇总字段是更优选择。
请用户提供:Flow类型、主要用途、触发对象/条件、目标组织别名。
后续操作:检查现有Flow(
Glob: **/*.flow-meta.xml
),提供
references/subflow-library.md
中的可复用子Flow,如需复杂自动化,请参考
references/governance-checklist.md

Phase 2: Flow Design & Template Selection

阶段2:Flow设计与模板选择

Flow TypeTemplate FileNaming Prefix
Screen
screen-flow-template.xml
Screen_
Record-Triggered (After)
record-triggered-*.xml
Auto_
Record-Triggered (Before)
record-triggered-*.xml
Before_
Scheduled
scheduled-flow-template.xml
Sched_
Platform Event
platform-event-flow-template.xml
Event_
Autolaunched
autolaunched-flow-template.xml
Sub_
or
Util_
Element Pattern Templates in
assets/elements/
: loop-pattern.xml, get-records-pattern.xml, record-delete-pattern.xml
Format:
[Prefix]_Object_Action
using PascalCase (e.g.,
Auto_Lead_Priority_Assignment
)
Screen Flow Buttons:
allowFinish="true"
required on all screens. Connector present → "Next", absent → "Finish".
CRITICAL: Record-triggered flows CANNOT call subflows via XML deployment. See
references/xml-gotchas.md
and
references/orchestration-guide.md
.
Flow类型模板文件命名前缀
屏幕流
screen-flow-template.xml
Screen_
记录触发流(保存后)
record-triggered-*.xml
Auto_
记录触发流(保存前)
record-triggered-*.xml
Before_
计划流
scheduled-flow-template.xml
Sched_
平台事件流
platform-event-flow-template.xml
Event_
自动启动流
autolaunched-flow-template.xml
Sub_
Util_
元素模式模板位于
assets/elements/
:loop-pattern.xml、get-records-pattern.xml、record-delete-pattern.xml
命名格式:采用帕斯卡命名法的
[前缀]_对象_操作
(例如:
Auto_Lead_Priority_Assignment
屏幕流按钮:所有屏幕必须设置
allowFinish="true"
。存在连接器时显示“下一步”,无连接器时显示“完成”。
重要提示:记录触发流无法通过XML部署调用子Flow。请参阅
references/xml-gotchas.md
references/orchestration-guide.md

Phase 3: Flow Generation & Validation

阶段3:Flow生成与验证

bash
mkdir -p force-app/main/default/flows
bash
mkdir -p force-app/main/default/flows

Write: force-app/main/default/flows/[FlowName].flow-meta.xml

写入:force-app/main/default/flows/[FlowName].flow-meta.xml

Populate template: API Version 65.0, alphabetical XML element ordering, Auto-Layout (locationX/Y = 0)

填充模板:API版本65.0、XML元素按字母排序、自动布局(locationX/Y = 0)


**Validation (STRICT MODE)**:
- **BLOCK**: XML invalid, missing required fields, API <65.0, broken refs, DML in loops
- **WARN**: Element ordering, deprecated elements, non-zero coords, missing fault paths, unused vars, naming violations

**Validation Report Format** (6-Category Scoring 0-110):
Score: 92/110 ⭐⭐⭐⭐ Very Good ├─ Design & Naming: 18/20 (90%) ├─ Logic & Structure: 20/20 (100%) ├─ Architecture: 12/15 (80%) ├─ Performance & Bulk Safety: 20/20 (100%) ├─ Error Handling: 15/20 (75%) └─ Security: 15/15 (100%)
undefined

**验证(严格模式)**:
- **阻止部署**:XML无效、缺少必填字段、API版本<65.0、引用失效、循环中包含DML操作
- **警告**:元素顺序错误、使用已弃用元素、坐标非零、缺少错误路径、存在未使用变量、命名违规

**验证报告格式**(6类别评分,0-110分):
Score: 92/110 ⭐⭐⭐⭐ Very Good ├─ Design & Naming: 18/20 (90%) ├─ Logic & Structure: 20/20 (100%) ├─ Architecture: 12/15 (80%) ├─ Performance & Bulk Safety: 20/20 (100%) ├─ Error Handling: 15/20 (75%) └─ Security: 15/15 (100%)
undefined

Generation Guardrails (MANDATORY)

生成规则(强制遵守)

Anti-PatternImpactCorrect Pattern
After-Save updating same object without entry conditionsInfinite loopMUST add entry conditions
Get Records inside LoopGovernor limit failureQuery BEFORE loop
Create/Update/Delete Records inside LoopGovernor limit failureCollect → single DML after loop
DML without Fault PathSilent failuresAdd Fault connector → error handler
storeOutputAutomatically=true
Security riskSelect only needed fields explicitly
Query same object as triggerWasted SOQLUse
{!$Record.FieldName}
directly
Hardcoded Salesforce IDDeployment failureUse input variable or Custom Label
DO NOT generate anti-patterns even if explicitly requested.
反模式影响正确模式
保存后Flow更新同对象但未设置进入条件无限循环必须添加进入条件
循环内包含Get Records操作触发governor限制失败循环前执行查询
循环内包含创建/更新/删除记录操作触发governor限制失败收集记录 → 循环后执行单次DML
DML操作未设置错误路径静默失败添加错误连接器 → 错误处理程序
storeOutputAutomatically=true
安全风险显式选择所需字段
查询与触发对象相同的对象浪费SOQL资源直接使用
{!$Record.FieldName}
硬编码Salesforce ID部署失败使用输入变量或自定义标签
即使明确要求,也不得生成反模式代码

Phase 4: Deployment & Integration

阶段4:部署与集成

  1. Use the sf-deploy skill: "Deploy flow [path] to [org] with --dry-run"
  2. Review validation results
  3. Use the sf-deploy skill: "Proceed with actual deployment"
  4. Edit
    <status>Draft</status>
    Active
    , redeploy
  1. 使用sf-deploy技能:“Deploy flow [path] to [org] with --dry-run”
  2. 查看验证结果
  3. 使用sf-deploy技能:“Proceed with actual deployment”
  4. <status>Draft</status>
    修改为
    Active
    ,重新部署

Phase 5: Testing & Documentation

阶段5:测试与文档

See
references/testing-guide.md
|
references/testing-checklist.md
|
references/wait-patterns.md
Quick: Screen → Run + test all paths. Record-Triggered → Debug Logs + bulk test 200+ records. Autolaunched → Apex test class. Scheduled → Verify schedule + manual Run.

请参阅
references/testing-guide.md
|
references/testing-checklist.md
|
references/wait-patterns.md
快速测试方法:屏幕流 → 运行并测试所有路径。记录触发流 → 调试日志 + 批量测试200+条记录。自动启动流 → Apex测试类。计划流 → 验证计划 + 手动运行。

Best Practices & Error Patterns

最佳实践与错误模式

See references/best-practices.md for full enforcement rules: record-triggered architecture, no parent traversal, recordLookups settings, XML element ordering, variable naming prefixes, and performance patterns.
Key rules: Never loop over
$Record
. No DML in loops. All DML needs fault paths. No parent traversal in Get Records. XML elements grouped alphabetically.
完整执行规则请参阅references/best-practices.md:记录触发流架构、禁止父对象遍历、recordLookups设置、XML元素排序、变量命名前缀、性能模式。
核心规则:切勿遍历
$Record
。禁止循环内执行DML。所有DML操作必须设置错误路径。Get Records中禁止父对象遍历。XML元素按字母分组排列。

Common Error Patterns

常见错误模式

Error PatternFix
DML in LoopCollect → single DML after loop
Self-Referencing FaultRoute fault to DIFFERENT element
Element DuplicatedGroup ALL same-type elements together
$Record__Prior
in Create-only
Only valid for Update/CreateAndUpdate triggers
"Parent.Field doesn't exist"Use TWO Get Records (child then parent)
See
references/xml-gotchas.md
for XML-specific issues.

错误模式修复方案
循环内执行DML收集记录 → 循环后执行单次DML
自引用错误路径将错误路由至不同元素
元素重复将所有同类型元素分组
仅创建触发中使用
$Record__Prior
仅在更新/创建并更新触发中有效
"Parent.Field不存在"使用两次Get Records(先子对象后父对象)
XML相关问题请参阅
references/xml-gotchas.md

Integration Patterns

集成模式

See references/integration-patterns.md for LWC-in-Flow XML patterns, Apex @InvocableMethod integration, and documentation links.
See references/agentforce-flow-integration.md for Agentforce variable name matching, output variable naming, formula limitations, and Action Definition registration (required for
flow://
targets in Agent Script).

LWC嵌入Flow的XML模式、Apex @InvocableMethod集成、文档链接请参阅references/integration-patterns.md
Agentforce集成请参阅references/agentforce-flow-integration.md:Agentforce变量名匹配、输出变量命名、公式限制、Action Definition注册(Agent脚本中
flow://
目标的必填项)。

Cross-Skill Integration

跨技能集成

From SkillTo sf-flowWhen
sf-ai-agentscript→ sf-flow"Create Autolaunched Flow for agent action"
sf-apex→ sf-flow"Create Flow wrapper for Apex logic"
sf-integration→ sf-flow"Create HTTP Callout Flow"
From sf-flowTo SkillWhen
sf-flow→ sf-metadata"Describe Invoice__c" (verify fields before flow)
sf-flow→ sf-deploy"Deploy flow with --dry-run"
sf-flow→ sf-data"Create 200 test Accounts" (after deploy)
来源技能目标sf-flow适用场景
sf-ai-agentscript→ sf-flow"为Agent操作创建自动启动Flow"
sf-apex→ sf-flow"为Apex逻辑创建Flow包装器"
sf-integration→ sf-flow"创建HTTP调用Flow"
来源sf-flow目标技能适用场景
sf-flow→ sf-metadata"描述Invoice__c"(Flow构建前验证字段)
sf-flow→ sf-deploy"Deploy flow with --dry-run"
sf-flow→ sf-data"创建200个测试账户"(部署后)

Flow Testing (CLI)

Flow测试(CLI)

bash
sf flow run test --test-names FlowTest1,FlowTest2 --target-org my-sandbox
sf flow run test --test-level RunAllFlowTests --target-org my-sandbox
sf flow get test --test-run-id <id> --target-org my-sandbox
GA since v2.86.9. For Apex tests, see
/sf-testing
. For unified runner (Beta):
sf logic run test
.

bash
sf flow run test --test-names FlowTest1,FlowTest2 --target-org my-sandbox
sf flow run test --test-level RunAllFlowTests --target-org my-sandbox
sf flow get test --test-run-id <id> --target-org my-sandbox
自v2.86.9起正式可用(GA)。Apex测试请参阅
/sf-testing
。统一测试运行器(Beta版):
sf logic run test

Edge Cases

边缘场景

ScenarioSolution
>200 recordsWarn limits, suggest scheduled flow
>5 branchesUse subflows
Cross-objectCheck circular deps, test recursion
ProductionDeploy Draft, activate explicitly
Debug: Flow not visible → deploy report + permissions | Tests fail → Debug Logs + bulk test | Sandbox→Prod fails → FLS + dependencies

场景解决方案
超过200条记录提示限制,建议使用计划流
分支超过5个使用子Flow
跨对象操作检查循环依赖,测试递归
生产环境部署先部署草稿版本,再手动激活
调试:Flow不可见 → 部署报告 + 权限检查 | 测试失败 → 调试日志 + 批量测试 | 沙盒→生产部署失败 → FLS(字段级安全) + 依赖项检查

Notes

注意事项

Dependencies (optional): sf-deploy, sf-metadata, sf-data | API: 65.0 | Mode: Strict (warnings block) | Python validators recommended
依赖项(可选):sf-deploy、sf-metadata、sf-data | API版本:65.0 | 模式:严格(警告会阻止部署) | 推荐使用Python验证器