@future(callout=true)
public static void processCaseLinks(String caseId) {// 提取描述中的链接Case caseRecord = [SELECT Id,Description FROM Case WHERE Id=:caseId];List<String> links = extractLinks(caseRecord.Description);List<Attachment> attachmentsToInsert = new List<Attachment>();for (String link : links) {try {// 下载文件并保存为附件HttpRequest req = new HttpRequest();req.setEndpoint(link);req.setMethod('GET');Http http = new Http();HttpResponse res = http.send(req);if (res.getStatusCode() == 200) {// 创建附件Attachment attachment = new Attachment();attachment.ParentId = caseRecord.Id;attachment.Name = getFileNameFromUrl(link);attachment.Body = res.getBodyAsBlob();attachment.ContentType = res.getHeader('Content-Type');attachmentsToInsert.add(attachment);}} catch (Exception e) {System.debug('Error processing link: ' + link + ' Error: ' + e.getMessage());}}if (!attachmentsToInsert.isEmpty()) {insert attachmentsToInsert;}
}