From 17bd5b18e21c9f46aefdbf3400262764f0def4da Mon Sep 17 00:00:00 2001
From: yumenghui <953181891@qq.com>
Date: 星期五, 04 八月 2023 15:12:14 +0800
Subject: [PATCH] 触发器附件修改

---
 force-app/main/default/triggers/SetAttToDocForEmail.trigger |   27 +++++++++++++++++++++------
 1 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/force-app/main/default/triggers/SetAttToDocForEmail.trigger b/force-app/main/default/triggers/SetAttToDocForEmail.trigger
index 58f8267..af91ba5 100644
--- a/force-app/main/default/triggers/SetAttToDocForEmail.trigger
+++ b/force-app/main/default/triggers/SetAttToDocForEmail.trigger
@@ -5,18 +5,33 @@
             Map<String, Schema.SObjectField> fieldMap = smarm.fields.getMap();
             
             List<Document> docList = new List<Document>();
-            // Attachment銈扗ocument銇�
-            for (Attachment att : ControllerUtil.getSmarmAtts(s.Id)) {
+            List<ContentDocumentLink> linkList = [SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId =: s.Id];
+            List<Id> linkIdList = new List<Id>();
+            for (ContentDocumentLink link : linkList) {
+                linkIdList.add(link.ContentDocumentId);
+            }
+            List<ContentVersion> versionList =[SELECT Title,VersionData FROM ContentVersion WHERE ContentDocumentId in: linkIdList];
+            for (ContentVersion cVersion : versionList) {
                 docList.add(new Document(
-                    Name = att.Name,
+                    Name = cVersion.Title,
                     DeveloperName = 'sm_' + s.Id + '_' + ControllerUtil.generateRandomStr(18),
                     Type = 'png',
-                    Body = att.Body
+                    Body = cVersion.VersionData
                 ));
             }
-            ControllerUtil.createDocForEmail(docList);
+            // Attachment銈扗ocument銇�
+            // for (Attachment att : ControllerUtil.getSmarmAtts(s.Id)) {
+            //     docList.add(new Document(
+            //         Name = att.Name,
+            //         DeveloperName = 'sm_' + s.Id + '_' + ControllerUtil.generateRandomStr(18),
+            //         Type = 'png',
+            //         Body = att.Body
+            //     ));
+            // }
+            List<Document> docInsertList = new List<Document>();
+            docInsertList = ControllerUtil.createDocForEmail(docList);
             Map<String, String> docMap = new Map<String, String>();
-            for (Document doc : docList) {
+            for (Document doc : docInsertList) {
                 docMap.put(doc.Name, doc.Id);
             }
             

--
Gitblit v1.9.1