要在Salesforce中实现创建案例时提取描述中的链接并自动下载并保存在附件中,可以使用Apex触发器结合HttpRequest和HttpResponse类来实现:
步骤概述
- 创建触发器:当案例(Case)被创建时触发。
- 编写Apex类:提取链接,下载文件,并将其保存为附件。
具体实现
1. 创建触发器
trigger CaseLinkAttachmentTrigger on Case (after insert) {
for (Case newCase : Trigger.new) {
if (newCase.Description != null) {
LinkAttachmentHelper.processCaseLinks(newCase);
}
}
}
2. 编写Apex Helper类
public class LinkAttachmentHelper {
@future(callout=true)
public static void processCaseLinks(Case caseRecord) {
// 提取描述中的链接
List<String> links = extractLinks(caseRecord.Description);
for (String link : links) {
try {
// 下载文件并保存为附件
HttpRequest