sf-flow
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesesf-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
核心职责
- Flow Generation: Create well-structured Flow metadata XML from requirements
- Strict Validation: Enforce best practices with comprehensive checks and scoring
- Safe Deployment: Integrate with sf-deploy skill for two-step validation and deployment
- Testing Guidance: Provide type-specific testing checklists and verification steps
- Flow生成:根据需求创建结构清晰的Flow元数据XML
- 严格验证:通过全面检查和评分体系执行最佳实践
- 安全部署:与sf-deploy技能集成,实现两步式验证与部署
- 测试指导:提供针对不同类型的测试清单和验证步骤
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 for extended patterns including Agentforce.
references/orchestration.mdsf-metadata → sf-flow → sf-deploy → sf-data(当前位置:sf-flow)
Flow引用了自定义对象/字段?请先使用sf-metadata创建它们。部署Flow前需先部署对象。如需包含Agentforce的扩展模式,请参阅。
references/orchestration.mdKey Insights
关键要点
| Insight | Details |
|---|---|
| Before vs After Save | Before-Save: same-record updates (no DML), validation. After-Save: related records, emails, callouts |
| Test with 251 | Batch boundary at 200. Test 251+ records for governor limits, N+1 patterns, bulk safety |
| $Record context | Single-record, NOT a collection. Platform handles batching. Never loop over $Record |
| Transform vs Loop | Transform: data mapping/shaping (30-50% faster). Loop: per-record decisions, counters, varying logic. See |
| 要点 | 详情 |
|---|---|
| 保存前 vs 保存后 | 保存前:同记录更新(无需DML)、验证。保存后:关联记录操作、发送邮件、外部调用 |
| 用251条数据测试 | 批量处理阈值为200条。测试251条以上数据,检查 governor 限制、N+1查询模式、批量处理安全性 |
| $Record 上下文 | 单记录上下文,而非集合。平台会处理批量操作。切勿遍历$Record |
| 转换 vs 循环 | 转换:数据映射/格式调整(速度快30-50%)。循环:单记录决策、计数、可变逻辑。请参阅 |
Workflow Design (5-Phase Pattern)
工作流设计(5阶段模式)
Phase 1: Requirements Gathering
阶段1:需求收集
Before building, evaluate alternatives: See Section 1 — sometimes a Formula Field, Validation Rule, or Roll-Up Summary is the better choice.
references/flow-best-practices.mdAsk the user to gather: flow type, primary purpose, trigger object/conditions, target org alias.
Then: Check existing flows (), offer reusable subflows from , reference for complex automation.
Glob: **/*.flow-meta.xmlreferences/subflow-library.mdreferences/governance-checklist.md构建前,请评估替代方案:参阅第1节——有时公式字段、验证规则或汇总字段是更优选择。
references/flow-best-practices.md请用户提供:Flow类型、主要用途、触发对象/条件、目标组织别名。
后续操作:检查现有Flow(),提供中的可复用子Flow,如需复杂自动化,请参考。
Glob: **/*.flow-meta.xmlreferences/subflow-library.mdreferences/governance-checklist.mdPhase 2: Flow Design & Template Selection
阶段2:Flow设计与模板选择
| Flow Type | Template File | Naming Prefix |
|---|---|---|
| Screen | | |
| Record-Triggered (After) | | |
| Record-Triggered (Before) | | |
| Scheduled | | |
| Platform Event | | |
| Autolaunched | | |
Element Pattern Templates in : loop-pattern.xml, get-records-pattern.xml, record-delete-pattern.xml
assets/elements/Format: using PascalCase (e.g., )
[Prefix]_Object_ActionAuto_Lead_Priority_AssignmentScreen Flow Buttons: required on all screens. Connector present → "Next", absent → "Finish".
allowFinish="true"CRITICAL: Record-triggered flows CANNOT call subflows via XML deployment. See and .
references/xml-gotchas.mdreferences/orchestration-guide.md| Flow类型 | 模板文件 | 命名前缀 |
|---|---|---|
| 屏幕流 | | |
| 记录触发流(保存后) | | |
| 记录触发流(保存前) | | |
| 计划流 | | |
| 平台事件流 | | |
| 自动启动流 | | |
元素模式模板位于:loop-pattern.xml、get-records-pattern.xml、record-delete-pattern.xml
assets/elements/命名格式:采用帕斯卡命名法的(例如:)
[前缀]_对象_操作Auto_Lead_Priority_Assignment屏幕流按钮:所有屏幕必须设置。存在连接器时显示“下一步”,无连接器时显示“完成”。
allowFinish="true"重要提示:记录触发流无法通过XML部署调用子Flow。请参阅和。
references/xml-gotchas.mdreferences/orchestration-guide.mdPhase 3: Flow Generation & Validation
阶段3:Flow生成与验证
bash
mkdir -p force-app/main/default/flowsbash
mkdir -p force-app/main/default/flowsWrite: 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%)
undefinedGeneration Guardrails (MANDATORY)
生成规则(强制遵守)
| Anti-Pattern | Impact | Correct Pattern |
|---|---|---|
| After-Save updating same object without entry conditions | Infinite loop | MUST add entry conditions |
| Get Records inside Loop | Governor limit failure | Query BEFORE loop |
| Create/Update/Delete Records inside Loop | Governor limit failure | Collect → single DML after loop |
| DML without Fault Path | Silent failures | Add Fault connector → error handler |
| Security risk | Select only needed fields explicitly |
| Query same object as trigger | Wasted SOQL | Use |
| Hardcoded Salesforce ID | Deployment failure | Use input variable or Custom Label |
DO NOT generate anti-patterns even if explicitly requested.
| 反模式 | 影响 | 正确模式 |
|---|---|---|
| 保存后Flow更新同对象但未设置进入条件 | 无限循环 | 必须添加进入条件 |
| 循环内包含Get Records操作 | 触发governor限制失败 | 循环前执行查询 |
| 循环内包含创建/更新/删除记录操作 | 触发governor限制失败 | 收集记录 → 循环后执行单次DML |
| DML操作未设置错误路径 | 静默失败 | 添加错误连接器 → 错误处理程序 |
| 安全风险 | 显式选择所需字段 |
| 查询与触发对象相同的对象 | 浪费SOQL资源 | 直接使用 |
| 硬编码Salesforce ID | 部署失败 | 使用输入变量或自定义标签 |
即使明确要求,也不得生成反模式代码。
Phase 4: Deployment & Integration
阶段4:部署与集成
- Use the sf-deploy skill: "Deploy flow [path] to [org] with --dry-run"
- Review validation results
- Use the sf-deploy skill: "Proceed with actual deployment"
- Edit →
<status>Draft</status>, redeployActive
- 使用sf-deploy技能:“Deploy flow [path] to [org] with --dry-run”
- 查看验证结果
- 使用sf-deploy技能:“Proceed with actual deployment”
- 将修改为
<status>Draft</status>,重新部署Active
Phase 5: Testing & Documentation
阶段5:测试与文档
See | |
references/testing-guide.mdreferences/testing-checklist.mdreferences/wait-patterns.mdQuick: 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.mdreferences/testing-checklist.mdreferences/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 . No DML in loops. All DML needs fault paths. No parent traversal in Get Records. XML elements grouped alphabetically.
$Record完整执行规则请参阅references/best-practices.md:记录触发流架构、禁止父对象遍历、recordLookups设置、XML元素排序、变量命名前缀、性能模式。
核心规则:切勿遍历。禁止循环内执行DML。所有DML操作必须设置错误路径。Get Records中禁止父对象遍历。XML元素按字母分组排列。
$RecordCommon Error Patterns
常见错误模式
| Error Pattern | Fix |
|---|---|
| DML in Loop | Collect → single DML after loop |
| Self-Referencing Fault | Route fault to DIFFERENT element |
| Element Duplicated | Group ALL same-type elements together |
| Only valid for Update/CreateAndUpdate triggers |
| "Parent.Field doesn't exist" | Use TWO Get Records (child then parent) |
See for XML-specific issues.
references/xml-gotchas.md| 错误模式 | 修复方案 |
|---|---|
| 循环内执行DML | 收集记录 → 循环后执行单次DML |
| 自引用错误路径 | 将错误路由至不同元素 |
| 元素重复 | 将所有同类型元素分组 |
仅创建触发中使用 | 仅在更新/创建并更新触发中有效 |
| "Parent.Field不存在" | 使用两次Get Records(先子对象后父对象) |
XML相关问题请参阅。
references/xml-gotchas.mdIntegration 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 fortargets in Agent Script).flow://
LWC嵌入Flow的XML模式、Apex @InvocableMethod集成、文档链接请参阅references/integration-patterns.md。
Agentforce集成请参阅references/agentforce-flow-integration.md:Agentforce变量名匹配、输出变量命名、公式限制、Action Definition注册(Agent脚本中目标的必填项)。flow://
Cross-Skill Integration
跨技能集成
| From Skill | To sf-flow | When |
|---|---|---|
| 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-flow | To Skill | When |
|---|---|---|
| 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-sandboxGA since v2.86.9. For Apex tests, see. For unified runner (Beta):/sf-testing.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测试请参阅。统一测试运行器(Beta版):/sf-testing。sf logic run test
Edge Cases
边缘场景
| Scenario | Solution |
|---|---|
| >200 records | Warn limits, suggest scheduled flow |
| >5 branches | Use subflows |
| Cross-object | Check circular deps, test recursion |
| Production | Deploy 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验证器