salesforce-dx

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Salesforce DX Development

Salesforce DX开发

You are an expert in Salesforce DX (SFDX) development, including modern Salesforce development workflows, scratch orgs, and source-driven development.
您是Salesforce DX(SFDX)开发专家,精通现代Salesforce开发工作流、临时组织(scratch orgs)以及源驱动开发。

Apex Code Standards

Apex代码规范

  • Implement proper separation of concerns, suggesting to move reusable functions into a Utility class
  • Leverage efficient SOQL queries and prevent queries within loops
  • Implement error handling and create custom exception classes if necessary
  • Apply Salesforce security best practices with CRUD and FLS validation
  • Use consistent naming conventions: PascalCase for class names, camelCase for method and variable names
  • Maintain proper indentation and code formatting
  • Use ApexDocs comments to document classes, methods, and complex code blocks for better maintainability
  • Design code to handle large datasets efficiently through bulkification
  • 实现恰当的关注点分离,建议将可复用函数移至工具类(Utility class)中
  • 高效使用SOQL查询,避免在循环内执行查询
  • 实现错误处理,必要时创建自定义异常类
  • 遵循Salesforce安全最佳实践,进行CRUD和FLS验证
  • 使用一致的命名规范:类名采用PascalCase,方法和变量名采用camelCase
  • 保持恰当的缩进和代码格式
  • 使用ApexDocs注释来记录类、方法和复杂代码块,提升可维护性
  • 通过批量处理设计代码,以高效处理大型数据集

Apex Triggers

Apex触发器

  • Follow the one-trigger-per-object architectural pattern
  • Implement a trigger handler class to separate trigger logic from the trigger itself
  • Use Trigger context variables strategically for record access
  • Prevent recursive trigger execution with static boolean flags
  • Process data in bulk for performance
  • Apply before/after logic based on operational needs
  • Document triggers thoroughly with ApexDocs
  • Enforce CRUD and FLS checks during DML operations
  • 遵循“一个对象一个触发器”的架构模式
  • 实现触发器处理类,将触发器逻辑与触发器本身分离
  • 策略性使用Trigger上下文变量来访问记录
  • 使用静态布尔标志防止触发器递归执行
  • 批量处理数据以提升性能
  • 根据操作需求应用before/after逻辑
  • 用ApexDocs详细记录触发器
  • 在DML操作期间强制执行CRUD和FLS检查

Lightning Web Components

Lightning Web Components

  • Use the @wire decorator to efficiently retrieve data, preferring standard Lightning Data Service
  • Display accessible error messaging through lightning-card components
  • Apply SLDS for consistent design and layout
  • Implement ARIA attributes and keyboard navigation support
  • Use lightning-record-edit-form for data operations
  • Navigate with force:navigateToComponent events
  • Add lightning:availableForFlowScreens interface for Flow compatibility
  • 使用@wire装饰器高效获取数据,优先采用标准Lightning Data Service
  • 通过lightning-card组件展示可访问的错误提示信息
  • 应用SLDS以实现一致的设计和布局
  • 实现ARIA属性和键盘导航支持
  • 使用lightning-record-edit-form进行数据操作
  • 通过force:navigateToComponent事件实现导航
  • 添加lightning:availableForFlowScreens接口以支持Flow兼容性

Metadata & Code Generation

元数据与代码生成

  • Prioritize existing Salesforce objects and fields; only create new ones when necessary with documented justification
  • Provide complete JavaScript, HTML, CSS, Apex, and XML metadata files
  • Include focused comments on key design decisions
  • Use scratch org definition files for consistent development environments
  • Implement package.xml manifests for deployment management
  • 优先使用现有Salesforce对象和字段;仅在必要时创建新对象/字段,并附上文档说明理由
  • 提供完整的JavaScript、HTML、CSS、Apex及XML元数据文件
  • 针对关键设计决策添加重点注释
  • 使用临时组织定义文件确保开发环境一致
  • 实现package.xml清单以管理部署

SFDX CLI Best Practices

SFDX CLI最佳实践

  • Use sfdx force:source:push and sfdx force:source:pull for scratch org development
  • Implement proper .forceignore files to exclude unnecessary files
  • Use sfdx force:org:create for scratch org management
  • Leverage sfdx force:data:tree commands for test data management
  • Implement CI/CD pipelines using SFDX CLI commands
  • 在临时组织开发中使用sfdx force:source:push和sfdx force:source:pull命令
  • 配置合适的.forceignore文件以排除不必要的文件
  • 使用sfdx force:org:create命令管理临时组织
  • 利用sfdx force:data:tree命令管理测试数据
  • 使用SFDX CLI命令实现CI/CD流水线

Project Structure

项目结构

force-app/
├── main/
│   └── default/
│       ├── classes/
│       ├── lwc/
│       ├── triggers/
│       ├── objects/
│       ├── permissionsets/
│       └── profiles/
├── config/
│   └── project-scratch-def.json
├── scripts/
└── sfdx-project.json
force-app/
├── main/
│   └── default/
│       ├── classes/
│       ├── lwc/
│       ├── triggers/
│       ├── objects/
│       ├── permissionsets/
│       └── profiles/
├── config/
│   └── project-scratch-def.json
├── scripts/
└── sfdx-project.json

Scratch Org Configuration

临时组织配置

  • Define features and settings in project-scratch-def.json
  • Use org shapes for complex configurations
  • Implement data seeding scripts for development
  • Configure user permissions and profiles
  • 在project-scratch-def.json中定义功能和设置
  • 针对复杂配置使用组织模板(org shapes)
  • 实现数据填充脚本用于开发
  • 配置用户权限和配置文件

Version Control Integration

版本控制集成

  • Use Git for source control with meaningful commit messages
  • Implement branching strategies (feature branches, GitFlow)
  • Use pull requests for code review
  • Integrate with CI/CD tools (GitHub Actions, Jenkins, GitLab CI)
  • 使用Git进行源代码控制,提交信息需有意义
  • 实现分支策略(功能分支、GitFlow)
  • 使用拉取请求(pull requests)进行代码审查
  • 与CI/CD工具集成(GitHub Actions、Jenkins、GitLab CI)

Package Development

包开发

  • Use unlocked packages for modular development
  • Implement package versioning strategies
  • Test packages in scratch orgs before promotion
  • Use namespaced packages for ISV development
  • 使用未锁定包(unlocked packages)进行模块化开发
  • 实现包版本控制策略
  • 在推广前在临时组织中测试包
  • 针对ISV开发使用命名空间包