From cd05a7b0ab8dd5838f8998fb36fc0435fd9c5b84 Mon Sep 17 00:00:00 2001 From: buli <137736985@qq.com> Date: 星期二, 11 七月 2023 14:07:40 +0800 Subject: [PATCH] LEX Community Code Deploy0711 --- force-app/main/default/classes/Batch_FixAttachmentToFiles.cls | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 42 insertions(+), 2 deletions(-) diff --git a/force-app/main/default/classes/Batch_FixAttachmentToFiles.cls b/force-app/main/default/classes/Batch_FixAttachmentToFiles.cls index e7b7f7a..06af07c 100644 --- a/force-app/main/default/classes/Batch_FixAttachmentToFiles.cls +++ b/force-app/main/default/classes/Batch_FixAttachmentToFiles.cls @@ -29,8 +29,10 @@ global void execute(Database.BatchableContext BC, List<Attachment> scope) { List<ContentVersion> insertContents = new List<ContentVersion>(); Map<string, id> nameParentMaps = new Map<string, id>(); + Set<String> attachmentIds = new Set<String>(); for (Attachment att : scope) { nameParentMaps.put(att.Name, att.ParentId); + attachmentIds.add(att.Id); ContentVersion cVersion = new ContentVersion(); cVersion.ContentLocation = 'S'; //S-Document is in Salesforce. E-Document is outside of Salesforce. L-Document is on a Social Netork. cVersion.PathOnClient = att.Name; //File name with extention @@ -42,7 +44,12 @@ if (insertContents.isEmpty()) { return; } - insert insertContents; + //Insert insertContents; + List<Database.SaveResult> saveResultsContents = Database.insert( + insertContents, + false + ); + insertLog(saveResultsContents, attachmentIds); set<Id> contentIds = new Set<Id>(); for (ContentVersion cv : insertContents) { contentIds.add(cv.id); @@ -61,7 +68,40 @@ cDocLink.Visibility = 'AllUsers'; insertDocLinks.add(cDocLink); } - insert insertDocLinks; + //Insert insertDocLinks; + List<Database.SaveResult> saveResultsLinks = Database.insert( + insertDocLinks, + false + ); + insertLog(saveResultsLinks, attachmentIds); + } + + global void insertLog( + List<Database.SaveResult> saveResults, + Set<String> attachmentIds + ) { + Transaction_Log__c traLog = new Transaction_Log__c(); + List<Map<String, String>> logMapList = new List<Map<String, String>>(); + for (Database.SaveResult result : saveResults) { + String recordId = result.getId(); + if (!result.isSuccess()) { + for (Database.Error error : result.getErrors()) { + Map<String, String> logMap = new Map<String, String>(); + String errorMsg = error.getMessage(); + logMap.put('recordId', recordId); + logMap.put('errorMsg', errorMsg); + logMapList.add(logMap); + } + } + } + if (logMapList.size() > 0) { + Map<String, String> attachmentIdMap = new Map<String, String>(); + attachmentIdMap.put('attachmentIds', JSON.serialize(attachmentIds)); + logMapList.add(attachmentIdMap); + traLog.Response__c = JSON.serialize(logMapList); + traLog.Module__c = 'Attachment COnvert Transaction '; + insert traLog; + } } global void finish(Database.BatchableContext BC) { -- Gitblit v1.9.1