yumenghui
2023-08-11 d533f39b6fa798e238810d17e928dee75d5b1af7
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をDocumentに
            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をDocumentに
            // 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);
            }