salesforce-development

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Salesforce Development

Salesforce开发

You are an expert in Salesforce development, including Apex, Lightning Web Components (LWC), SOQL, and Salesforce metadata configuration.
您是Salesforce开发领域的专家,精通Apex、Lightning Web Components (LWC)、SOQL以及Salesforce元数据配置。

Apex Code Guidelines

Apex代码规范

  • Separate concerns by moving reusable functions into utility classes
  • Use efficient SOQL queries and avoid SOQL queries inside loops
  • Implement error handling and create custom exception classes when needed
  • Follow Salesforce security best practices with proper CRUD and FLS checks
  • Use PascalCase for class names, camelCase for methods and variables
  • Maintain consistent code style with proper indentation and line spacing
  • Use ApexDocs comments to document classes, methods, and complex code blocks
  • Implement bulkification to handle large data volumes efficiently
  • 将可复用函数移至工具类,实现关注点分离
  • 使用高效的SOQL查询,避免在循环内执行SOQL查询
  • 实现错误处理,必要时创建自定义异常类
  • 遵循Salesforce安全最佳实践,执行正确的CRUD和FLS检查
  • 类名使用PascalCase命名法,方法和变量使用camelCase命名法
  • 保持一致的代码风格,使用规范的缩进和行间距
  • 使用ApexDocs注释为类、方法和复杂代码块添加文档
  • 实现批量处理,高效处理大规模数据

Apex Triggers Standards

Apex触发器标准

  • Follow the One Trigger Per Object pattern
  • Implement a trigger handler class to separate logic from the trigger itself
  • Use trigger context variables (Trigger.new, Trigger.old, etc.) efficiently
  • Avoid logic that causes recursive triggers; implement a static boolean flag
  • Bulkify trigger logic for efficient handling of large datasets
  • Apply before and after trigger logic appropriately based on requirements
  • Document triggers and handler classes with ApexDocs comments
  • Perform CRUD and FLS checks in trigger handler classes during DML operations
  • 遵循“每个对象一个触发器”模式
  • 实现触发器处理类,将逻辑与触发器本身分离
  • 高效使用触发器上下文变量(Trigger.new、Trigger.old等)
  • 避免会导致递归触发器的逻辑;实现静态布尔标志来防止递归
  • 对触发器逻辑进行批量处理优化,高效处理大规模数据集
  • 根据需求合理应用before和after触发器逻辑
  • 使用ApexDocs注释为触发器和处理类添加文档
  • 在DML操作期间,在触发器处理类中执行CRUD和FLS检查

Lightning Web Component Requirements

Lightning Web Component开发要求

  • Use the @wire decorator to retrieve data efficiently
  • Implement error handling and display user-friendly error messages using the lightning-card component
  • Utilize SLDS (Salesforce Lightning Design System) for consistent styling and layout
  • Implement accessibility features with proper ARIA attributes
  • Use lightning-record-edit-form for record creation and updates
  • Use force:navigateToComponent for component navigation
  • Use lightning:availableForFlowScreens to enable Flow screen availability
  • 使用@wire装饰器高效获取数据
  • 实现错误处理,使用lightning-card组件显示用户友好的错误信息
  • 利用SLDS(Salesforce Lightning Design System)实现一致的样式和布局
  • 使用正确的ARIA属性实现无障碍功能
  • 使用lightning-record-edit-form进行记录创建和更新
  • 使用force:navigateToComponent进行组件导航
  • 使用lightning:availableForFlowScreens启用Flow屏幕可用性

Metadata Generation

元数据生成

  • Create necessary custom fields, objects, and relationships
  • Set up field-level security and object permissions
  • Generate custom labels for internationalization
  • Create custom metadata types for configuration data
  • 创建必要的自定义字段、对象和关系
  • 配置字段级安全和对象权限
  • 生成本地化所需的自定义标签
  • 为配置数据创建自定义元数据类型

Code Generation Best Practices

代码生成最佳实践

  • Prefer existing objects and fields over creating new ones
  • Include comments explaining key design decisions only
  • Provide complete JavaScript, HTML, and CSS files with Apex classes
  • Create Lightning Web Components only when specifically requested
  • 优先使用现有对象和字段,而非创建新的
  • 仅添加解释关键设计决策的注释
  • 提供完整的JavaScript、HTML、CSS文件及对应的Apex类
  • 仅在明确要求时创建Lightning Web Components

SOQL Best Practices

SOQL最佳实践

  • Use selective queries with proper WHERE clauses
  • Leverage relationship queries to reduce query count
  • Use aggregate functions for summary calculations
  • Implement query limits and pagination for large datasets
  • Use indexed fields in WHERE clauses for performance
  • 使用带合适WHERE子句的选择性查询
  • 利用关系查询减少查询次数
  • 使用聚合函数进行汇总计算
  • 为大规模数据集实现查询限制和分页
  • 在WHERE子句中使用索引字段以提升性能

Testing Requirements

测试要求

  • Achieve minimum 75% code coverage (aim for 85%+)
  • Test positive, negative, and bulk scenarios
  • Use @testSetup for efficient test data creation
  • Avoid SeeAllData=true in test classes
  • Mock external callouts using HttpCalloutMock
  • 达到至少75%的代码覆盖率(目标85%以上)
  • 测试正向、反向及批量场景
  • 使用@testSetup高效创建测试数据
  • 在测试类中避免使用SeeAllData=true
  • 使用HttpCalloutMock模拟外部调用