global class FileBatchDeleteController {
|
|
//先删除salesforce的附件
|
WebService static String fileSFDelete(List<String> idList){
|
Savepoint sp = Database.setSavepoint();
|
try{
|
//sf删除
|
Database.delete(idList);
|
return 'success';
|
}catch(Exception e){
|
Database.rollback(sp);
|
System.debug('失败原因是 : ' + e.getMessage());
|
return '失败原因是 : ' + e.getMessage();
|
}
|
}
|
|
//再删除AWS那边的附件
|
WebService static String fileAWSDelete(List<String> keyList){
|
try {
|
// System.debug('keyList = ' + keyList);
|
// Map<String,List<String>> keyMap = new Map<String,List<String>>();
|
// keyMap.put('keys' , keyList);
|
String keyJson = JSON.serialize(keyList);
|
System.debug('keyJson = ' + keyJson);
|
|
String deleteUrl = '';
|
PIHelper.PIIntegration staticResource = null;
|
AWS_Integration_Info__mdt awsConfiguration = [SELECT App_Id__c,Token_URL__c,App_Secret__c,Host_URL__c FROM AWS_Integration_Info__mdt WHERE DeveloperName = 'AWS_Default_Configuration'];
|
if (awsConfiguration == null) {
|
System.debug('AWS_Integration_Info__mdt没配置');
|
return 'AWS_Integration_Info__mdt没配置';
|
}else {
|
deleteUrl = awsConfiguration.Host_URL__c + '/api/file/delete';
|
staticResource = PIHelper.getPIIntegrationInfo('Document');
|
}
|
Http http = new Http();
|
HttpRequest request = new HttpRequest();
|
// 设置网络服务接口的地址
|
request.setEndpoint(deleteUrl);
|
// 设置REST方法
|
request.setMethod('POST');
|
// 设置请求的Header,类型为JSON
|
request.setHeader('Content-Type', 'application/json');
|
// 设置请求的token
|
request.setHeader('pi-token', staticResource.token);
|
// 将一个JSON对象传入请求的Body,设置编程语言的名字
|
request.setBody(keyJson);
|
// 发送HTTP请求
|
HttpResponse response = http.send(request);
|
System.debug(response);
|
// 检查HTTP通信结果状态代码
|
if (response.getStatusCode() == 200) {
|
//在控制台输出通信结果
|
System.debug(response.getBody());
|
}
|
return 'success';
|
} catch (Exception e) {
|
System.debug('失败原因是 : ' + e.getMessage());
|
return '失败原因是 : ' + e.getMessage();
|
}
|
}
|
}
|