From e6068da47c1bef5517c9e5fdc8c726766867ad4e Mon Sep 17 00:00:00 2001
From: buli <137736985@qq.com>
Date: 星期五, 14 七月 2023 15:10:02 +0800
Subject: [PATCH] Merge branch 'master' into LEXUpgrade2023-Deloitte

---
 force-app/main/default/classes/Batch_FixAttachmentToFiles.cls |   12 ++++--------
 1 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/force-app/main/default/classes/Batch_FixAttachmentToFiles.cls b/force-app/main/default/classes/Batch_FixAttachmentToFiles.cls
index 1d917ed..a3e8c1a 100644
--- a/force-app/main/default/classes/Batch_FixAttachmentToFiles.cls
+++ b/force-app/main/default/classes/Batch_FixAttachmentToFiles.cls
@@ -27,11 +27,11 @@
         Map<string, id> nameParentMaps = new Map<string, id>();
         Set<String> attachmentIds = new Set<String>();
         for (Attachment att : scope) {
-            nameParentMaps.put(att.Name, att.ParentId);
+            nameParentMaps.put(att.Id, 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
+            cVersion.PathOnClient = att.Id; //File name with extention
             cVersion.Origin = 'C'; //C-Content Origin. H-Chatter Origin.
             cVersion.Title = att.Name; //Name of the file
             cVersion.VersionData = att.Body; //File content
@@ -47,16 +47,12 @@
         for (ContentVersion cv : insertContents) {
             contentIds.add(cv.id);
         }
-        List<ContentVersion> conDocuments = [
-            SELECT ContentDocumentId, Title
-            FROM ContentVersion
-            WHERE Id IN :contentIds
-        ];
+        List<ContentVersion> conDocuments = [SELECT ContentDocumentId, Title, PathOnClient FROM ContentVersion WHERE Id IN :contentIds];
         List<ContentDocumentLink> insertDocLinks = new List<ContentDocumentLink>();
         for (ContentVersion cv : conDocuments) {
             ContentDocumentLink cDocLink = new ContentDocumentLink();
             cDocLink.ContentDocumentId = cv.ContentDocumentId; //Add ContentDocumentId
-            cDocLink.LinkedEntityId = nameParentMaps.get(cv.Title); //Add attachment parentId
+            cDocLink.LinkedEntityId = nameParentMaps.get(cv.PathOnClient); //Add attachment parentId
             cDocLink.ShareType = 'V'; //V - Viewer permission. C - Collaborator permission. I - Inferred permission.
             cDocLink.Visibility = 'AllUsers';
             insertDocLinks.add(cDocLink);

--
Gitblit v1.9.1