Apex Tooling API 使用教程
1、项目的目录结构及介绍
apex-toolingapi/
├── examples/
│ └── code_coverage_chart/
│ └── src/
├── LICENSE
├── README.md
└── gitignore
- examples/: 包含示例代码,例如
code_coverage_chart
目录下的src
文件夹。 - LICENSE: 项目的许可证文件,采用 BSD-3-Clause 许可证。
- README.md: 项目的说明文档。
- gitignore: Git 忽略文件配置。
2、项目的启动文件介绍
项目的主要启动文件位于 examples/code_coverage_chart/src
目录下。具体文件包括:
- ToolingAPIService.cls: 这是一个示例类,展示了如何使用 Tooling API 部署 Apex 类。
public class ToolingAPIService {
// Method to deploy an Apex class using Tooling API
public static void deployApexClass(String className, String classBody) {
try {
// Create the Tooling API metadata container
MetadataContainer container = new MetadataContainer();
insert container;
// Create the Tooling API ApexClassMember
ApexClassMember classMember = new ApexClassMember();
classMember.MetadataContainerId = container.Id;
classMember.ContentEntityId = className;
classMember.Body = classBody;
insert classMember;
// Create the Tooling API ContainerAsyncRequest
ContainerAsyncRequest deployRequest = new ContainerAsyncRequest();
deployRequest.MetadataContainerId = container.Id;
deployRequest.IsCheckOnly = false; // Set to true for validation-only
} catch (Exception e) {
System.debug(e.getMessage());
}
}
}
3、项目的配置文件介绍
项目的配置文件主要是 gitignore
文件,用于指定 Git 版本控制系统在提交代码时忽略的文件和目录。
# Ignore all files in the examples directory
examples/
# Ignore all log files
*.log
# Ignore all temporary files
*.tmp
这个配置文件确保了示例代码和临时文件不会被提交到版本控制系统中,保持代码库的整洁。