3.8 KiB
3.8 KiB
Apex 细粒度元数据操作需求
元数据
- 需求编号:013-4
- 父需求:013
- 创建时间:2026-01-26
- 创建人:SSOT 架构师
- 状态:进行中
- 优先级:中
- 关联代码:
com.sforce.soap.apex.SoapConnectioncom.sforce.soap.apex.CompileClasses_elementcom.sforce.soap.apex.CompileClassResultcom.sforce.soap.apex.CompileTriggers_elementcom.sforce.soap.apex.CompileTriggerResult
需求概述
提供基于源码的细粒度编译功能,支持直接对 Apex 类和触发器进行即时编译(Compile),作为 Metadata API 部署(Deploy)的轻量级替代方案,适用于开发阶段的快速迭代。
目标
- 实现 Apex 类的即时编译与保存。
- 实现 Apex 触发器的即时编译与保存。
- 注意:当前项目
SoapConnection暂不支持deleteApex操作,故本需求不包含删除功能。
功能需求
1. 编译 Apex 类 (Compile Classes)
- 功能描述:封装
SoapConnection.compileClasses。 - 接口定义:
List<CompileResult> compileClasses(List<String> classSources); - 输入参数:
classSources: Apex 类的完整源码字符串列表(对应 SOAPscripts字段,类型String[])。
- 处理逻辑:
- 构建
CompileClasses_element。 - 设置
scripts为传入的源码列表。 - 调用
connection.compileClasses(scripts)。 - 将返回的
CompileClassResult[]转换为统一的CompileResultVO (引用 REQ-013-1)。
- 构建
- 输出:
- 返回
CompileResult列表,包含每个类的success,id,name,problem,line,column,bodyCrc,problems,warnings等信息。
- 返回
2. 编译 Apex 触发器 (Compile Triggers)
- 功能描述:封装
SoapConnection.compileTriggers。 - 接口定义:
List<CompileResult> compileTriggers(List<String> triggerSources); - 输入参数:
triggerSources: Apex 触发器的完整源码字符串列表(对应 SOAPscripts字段,类型String[])。
- 处理逻辑:
- 构建
CompileTriggers_element。 - 设置
scripts为传入的源码列表。 - 调用
connection.compileTriggers(scripts)。 - 将返回的
CompileTriggerResult[]转换为统一的CompileResultVO。
- 构建
- 输出:
- 返回
CompileResult列表。
- 返回
关键代码映射 (Source Code Mapping)
SOAP 对象映射
| 逻辑概念 | SOAP 类名 | 关键字段 |
|---|---|---|
| 类编译请求 | CompileClasses_element |
scripts (String[]) |
| 类编译响应 | CompileClassResult |
id, name, success, problem, line, column, bodyCrc, problems, warnings |
| 触发器编译请求 | CompileTriggers_element |
scripts (String[]) |
| 触发器编译响应 | CompileTriggerResult |
id, name, success, problem, line, column, bodyCrc, problems, warnings |
异常处理规范
- 编译失败:当
CompileClassResult.success为false时,不抛出异常,而是返回包含错误信息的CompileResult对象,让前端展示具体的编译错误(行号、列号、错误消息)。 - SOAP 故障:网络或认证错误抛出
ConnectionException。
验证与测试
- 有效类编译:传入有效的 Apex 类源码,断言返回
success=true且id不为空。 - 无效类编译:传入包含语法错误的源码,断言返回
success=false,且line和problem字段准确指示错误位置和原因。 - 有效触发器编译:传入有效的 Apex 触发器源码,断言编译成功。
- 批量编译:传入多个源码文件,验证批量处理能力。