yumenghui
2023-08-04 17bd5b18e21c9f46aefdbf3400262764f0def4da
触发器附件修改
2个文件已修改
42 ■■■■ 已修改文件
force-app/main/default/triggers/SetAttToDocForEmail.trigger 27 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/triggers/TemporaryFileBoxUpdate.trigger 15 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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);
            }
            
force-app/main/default/triggers/TemporaryFileBoxUpdate.trigger
@@ -7,12 +7,19 @@
        }
    }
    if (tfbIds.size() > 0) {
        // List<ContentDocumentLink> linkList = [SELECT LinkedEntityId,ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId IN: tfbIds];
        Map<Id, AggregateResult> arMap = new Map<Id, AggregateResult>(
                [SELECT ParentId Id, Count(Id) Cnt_Id
                   FROM Attachment
                  WHERE ParentId IN :tfbIds
                  GROUP BY ParentId
            [SELECT LinkedEntityId Id, Count(ContentDocumentId) Cnt_Id
               FROM ContentDocumentLink
              WHERE LinkedEntityId IN :tfbIds
              GROUP BY LinkedEntityId
        ]);
        // Map<Id, AggregateResult> arMap = new Map<Id, AggregateResult>(
        //         [SELECT ParentId Id, Count(Id) Cnt_Id
        //            FROM Attachment
        //           WHERE ParentId IN :tfbIds
        //           GROUP BY ParentId
        // ]);
        for(TemporaryFileBox__c tfb : Trigger.new) {
            AggregateResult ar = arMap.get(tfb.Id);
            if (ar == null || Integer.valueOf(ar.get('Cnt_Id')) == 0) {