force-app/main/default/classes/AttachmentReQisHandler.cls
@@ -5,18 +5,18 @@ */ public without sharing class AttachmentReQisHandler extends Oly_TriggerHandler{ @TestVisible private Map<Id, Attachment> newMap; private Map<Id, ContentDocumentLink> newMap; @TestVisible private Map<Id, Attachment> oldMap; private Map<Id, ContentDocumentLink> oldMap; @TestVisible private List<Attachment> newList; private List<ContentDocumentLink> newList; @TestVisible private List<Attachment> oldList; private List<ContentDocumentLink> oldList; public AttachmentReQisHandler() { this.newMap = (Map<Id, Attachment>) Trigger.newMap; this.oldMap = (Map<Id, Attachment>) Trigger.oldMap; this.newList = (List<Attachment>) Trigger.new; this.oldList = (List<Attachment>) Trigger.old; this.newMap = (Map<Id, ContentDocumentLink>) Trigger.newMap; this.oldMap = (Map<Id, ContentDocumentLink>) Trigger.oldMap; this.newList = (List<ContentDocumentLink>) Trigger.new; this.oldList = (List<ContentDocumentLink>) Trigger.old; } @TestVisible protected override void afterInsert() { @@ -24,19 +24,32 @@ NoteMail(); } private void NoteMail() { List<Id> linkIdList = new List<Id>(); for (ContentDocumentLink link : newList) { linkIdList.add(link.Id); } newList = [select Id,LinkedEntityId,ContentDocumentId from ContentDocumentLink where Id in: linkIdList]; String baseUrl = URL.getSalesforceBaseUrl().toExternalForm(); List<Messaging.SingleEmailMessage> sendMails = new List<Messaging.SingleEmailMessage>(); List<String> Rlist = new List<String>(); List<String> ParentIdList = new List<String>(); // QisID for (Attachment att : newList) { if(String.valueOf(att.ParentId).startsWith('a0J') || String.valueOf(att.ParentId).startsWith('a0f')){ Rlist.add(att.Id); ParentIdList.add(att.ParentId); for (ContentDocumentLink link : newList) { if(String.valueOf(link.LinkedEntityId).startsWith('a0J') || String.valueOf(link.LinkedEntityId).startsWith('a0f')){ Rlist.add(link.ContentDocumentId); ParentIdList.add(link.LinkedEntityId); } } List<Attachment> NtList = [Select id,ParentId,Name,Body FROM Attachment where Id in : Rlist]; // for (Attachment att : newList) { // if(String.valueOf(att.ParentId).startsWith('a0J') // || String.valueOf(att.ParentId).startsWith('a0f')){ // Rlist.add(att.Id); // ParentIdList.add(att.ParentId); // } // } // List<Attachment> NtList = [Select id,ParentId,Name,Body FROM Attachment where Id in : Rlist]; List<ContentVersion> verList = [select Id,Title,VersionData,ContentDocumentId from ContentVersion where ContentDocumentId in: Rlist]; Map<Id,Repair__c> updateRprMap = new Map<Id,Repair__c>(); Map<Id,QIS_Report__c> updateQisMap = new Map<Id,QIS_Report__c>(); for (Repair__c re :[select id,Name,SerialNumber__c,Delivered_Product__r.Name,HP_Name__c @@ -61,11 +74,12 @@ } } List<User> userList = [select Id, Name, Email, Manager.Email from User where id IN :IdList]; for (Attachment nt : NtList) { String titName = updateRprMap.containsKey(nt.ParentId)? updateRprMap.get(nt.ParentId).Name : updateQisMap.get(nt.ParentId).Name; String prname = updateRprMap.containsKey(nt.ParentId)? updateRprMap.get(nt.ParentId).Delivered_Product__r.Name : updateQisMap.get(nt.ParentId).nonyushohin__r.Name; String Serial = updateRprMap.containsKey(nt.ParentId)? updateRprMap.get(nt.ParentId).SerialNumber__c : updateQisMap.get(nt.ParentId).lot_or_serial__c; String accountname = updateRprMap.containsKey(nt.ParentId)? updateRprMap.get(nt.ParentId).HP_Name__c : updateQisMap.get(nt.ParentId).Hospital__r.Name; for (ContentVersion version : verList) { ContentDocumentLink link = [select LinkedEntityId from ContentDocumentLink where ContentDocumentId =: version.ContentDocumentId limit 1]; String titName = updateRprMap.containsKey(link.LinkedEntityId)? updateRprMap.get(link.LinkedEntityId).Name : updateQisMap.get(link.LinkedEntityId).Name; String prname = updateRprMap.containsKey(link.LinkedEntityId)? updateRprMap.get(link.LinkedEntityId).Delivered_Product__r.Name : updateQisMap.get(link.LinkedEntityId).nonyushohin__r.Name; String Serial = updateRprMap.containsKey(link.LinkedEntityId)? updateRprMap.get(link.LinkedEntityId).SerialNumber__c : updateQisMap.get(link.LinkedEntityId).lot_or_serial__c; String accountname = updateRprMap.containsKey(link.LinkedEntityId)? updateRprMap.get(link.LinkedEntityId).HP_Name__c : updateQisMap.get(link.LinkedEntityId).Hospital__r.Name; String title = ''; String body = ''; title = '【修理/QIS】:' + titName + '已新增附件,请查看'; @@ -75,12 +89,12 @@ body += '<br/>'; body += '机身号/批号 :' + Serial; body += '<br/>'; body += '附件名称/备注名称:' + nt.Name; body += '附件名称/备注名称:' + version.Title; body += '<br/>'; body += '操作担当:' + UserInfo.getName(); body += '<br/>'; body += '<br/>'; body += '链接:' + baseUrl + '/' + nt.ParentId +' '; body += '链接:' + baseUrl + '/' + link.LinkedEntityId +' '; //收件邮箱 List<String> toMailList = new List<String>(); String uId = UserInfo.getUserId(); @@ -91,8 +105,9 @@ } //抄送的邮箱 List<String> ccMailList = new List<String>(); ccMailList.add('gaozhangwei@prec-tech.com'); ccMailList.add('wei_liang@olympus.com.cn'); // ccMailList.add('gaozhangwei@prec-tech.com'); // ccMailList.add('wei_liang@olympus.com.cn'); ccMailList.add('chenjingwu@prec-tech.com'); Messaging.SingleEmailMessage messageNEW = new Messaging.SingleEmailMessage(); messageNEW.subject = title; messageNEW.htmlBody = body; @@ -103,6 +118,48 @@ } sendMails.add(messageNEW); } // for (Attachment nt : NtList) { // String titName = updateRprMap.containsKey(nt.ParentId)? updateRprMap.get(nt.ParentId).Name : updateQisMap.get(nt.ParentId).Name; // String prname = updateRprMap.containsKey(nt.ParentId)? updateRprMap.get(nt.ParentId).Delivered_Product__r.Name : updateQisMap.get(nt.ParentId).nonyushohin__r.Name; // String Serial = updateRprMap.containsKey(nt.ParentId)? updateRprMap.get(nt.ParentId).SerialNumber__c : updateQisMap.get(nt.ParentId).lot_or_serial__c; // String accountname = updateRprMap.containsKey(nt.ParentId)? updateRprMap.get(nt.ParentId).HP_Name__c : updateQisMap.get(nt.ParentId).Hospital__r.Name; // String title = ''; // String body = ''; // title = '【修理/QIS】:' + titName + '已新增附件,请查看'; // body += '用户名:' + accountname; // body += '<br/>'; // body += '产品名称/型号 :' + prname; // body += '<br/>'; // body += '机身号/批号 :' + Serial; // body += '<br/>'; // body += '附件名称/备注名称:' + nt.Name; // body += '<br/>'; // body += '操作担当:' + UserInfo.getName(); // body += '<br/>'; // body += '<br/>'; // body += '链接:' + baseUrl + '/' + nt.ParentId +' '; // //收件邮箱 // List<String> toMailList = new List<String>(); // String uId = UserInfo.getUserId(); // for (User u : userList) { // if (u.Id != uId) { // toMailList.add(u.Email); // } // } // //抄送的邮箱 // List<String> ccMailList = new List<String>(); // ccMailList.add('gaozhangwei@prec-tech.com'); // ccMailList.add('wei_liang@olympus.com.cn'); // Messaging.SingleEmailMessage messageNEW = new Messaging.SingleEmailMessage(); // messageNEW.subject = title; // messageNEW.htmlBody = body; // messageNEW.setCharset('UTF-8'); // messageNEW.toAddresses = toMailList; // if(ccMailList.size() > 0){ // messageNEW.ccAddresses = ccMailList; // } // sendMails.add(messageNEW); // } //在单个事务中,只能调用send方法 10 次。 Messaging.SendEmailResult[] results = messaging.sendEmail(sendMails); } force-app/main/default/classes/AttachmentReQisHandler.cls-meta.xml
@@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> <ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> <apiVersion>41.0</apiVersion> <apiVersion>43.0</apiVersion> <status>Active</status> </ApexClass> force-app/main/default/classes/AttachmentReQisHandlerTest.cls
New file @@ -0,0 +1,158 @@ @isTest private class AttachmentReQisHandlerTest { private static Id pricebookId = ControllerUtil.getStandardPricebook().Id; static testMethod void testMethod1() { // 病院を作る Account hospital = new Account(); hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id; hospital.Name = 'test hospital'; insert hospital; // 戦略科室を得る List<Account> strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI']; // 診療科を作る Account dep = new Account(); dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'].id; dep.Name = 'test dep'; dep.ParentId = strategicDep[0].Id; dep.Department_Class__c = strategicDep[0].Id; dep.Hospital__c = hospital.Id; insert dep; // 製品を作る Product2 productA = new Product2( Name='テスト商品'); insert productA; // 価格表エントリを作成する PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=productA.Id); entry.UnitPrice = 0; entry.IsActive = true; entry.UseStandardPrice = false; entry.CurrencyIsoCode = 'CNY'; entry.Product2Id = productA.Id; insert entry; // 納入機器を作成する Asset asset = new Asset(); asset.Name = 'テスト機器'; asset.AccountId = dep.Id; asset.Department_Class__c = strategicDep[0].Id; asset.Hospital__c = hospital.Id; asset.SerialNumber = 'testserial'; insert asset; // 维修合同を作成する Maintenance_Contract__c contract = new Maintenance_Contract__c(); contract.Name = 'tect contract'; contract.Hospital__c = hospital.Id; contract.Department_Class__c = strategicDep[0].Id; contract.Department__c = dep.Id; insert contract; // 修理を作成する Repair__c repair = new Repair__c(); repair.Account__c = dep.Id; repair.Department_Class__c = strategicDep[0].Id; repair.Hospital__c = hospital.Id; repair.Delivered_Product__c = asset.Id; insert repair; // Attachment att = new Attachment( // Name = 'test', // ParentId = repair.Id, // Body = EncodingUtil.base64Decode('test') // ); ContentVersion version = new ContentVersion( Title = 'test', VersionData = EncodingUtil.base64Decode('test'), ContentLocation = 's', PathOnClient = 'test.txt' ); insert version; version = [select ContentDocumentId from ContentVersion where Id =: version.Id]; ContentDocumentLink link = new ContentDocumentLink(); link.ContentDocumentId = version.ContentDocumentId; link.LinkedEntityId = repair.Id; link.ShareType = 'I'; link.Visibility = 'AllUsers'; insert link; } // 覆盖率补充 static testMethod void testMethod2() { List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院']; if (rectCo.size() == 0) { return; } List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科']; if (rectSct.size() == 0) { return; } List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科']; if (rectDpt.size() == 0) { return; } StaticParameter.EscapeOpportunityBefUpdTrigger = true; StaticParameter.EscapeSyncOpportunityTrigger = true; StaticParameter.EscapeNFM007Trigger = true; StaticParameter.EscapeOpportunityHpDeptUpdTrigger = true; StaticParameter.EscapeSyncOpportunityTrigger = true; // テストデータ Account company = new Account(); company.RecordTypeId = rectCo[0].Id; company.Name = 'NFM007TestCompany'; upsert company; Account section = new Account(); section.RecordTypeId = rectSct[0].Id; section.Name = '*'; section.Department_Class_Label__c = '消化科'; section.ParentId = company.Id; section.Hospital_Department_Class__c = company.Id; upsert section; Account depart = new Account(); depart.RecordTypeId = rectDpt[0].Id; depart.Name = '*'; depart.Department_Name__c = 'NFM007TestDepart'; depart.ParentId = section.Id; depart.Department_Class__c = section.Id; depart.Hospital__c = company.Id; upsert depart; Opportunity opp = new Opportunity(); opp.AccountId = depart.Id; opp.Department_Class__c = section.Id; opp.Hospital__c = company.Id; opp.SAP_Send_OK__c = false; opp.Name = 'GZ-SP-NFM007_1'; opp.Trade__c = '内貿'; opp.StageName = '引合'; opp.CloseDate = Date.today().adddays(1); opp.Stock_apply_status__c = '申请中'; insert opp; Opportunity_File__c ofile = new Opportunity_File__c(); ofile.Name = 'test file'; ofile.Opportunity__c = opp.Id; ofile.Oppor_File_Stage__c = 'G'; insert ofile; ContentVersion version = new ContentVersion( Title = 'test', VersionData = EncodingUtil.base64Decode('test'), ContentLocation = 's', PathOnClient = 'test.txt' ); insert version; version = [select ContentDocumentId from ContentVersion where Id =: version.Id]; ContentDocumentLink link = new ContentDocumentLink(); link.ContentDocumentId = version.ContentDocumentId; link.LinkedEntityId = ofile.Id; link.ShareType = 'I'; link.Visibility = 'AllUsers'; insert link; delete ofile; } } force-app/main/default/classes/AttachmentReQisHandlerTest.cls-meta.xml
New file @@ -0,0 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> <ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> <apiVersion>57.0</apiVersion> <status>Active</status> </ApexClass> force-app/main/default/classes/StaticParameter.cls
@@ -66,7 +66,8 @@ // 预测跳过询价和注残 public static Boolean EscapeOppandStaTrigger = false; //跳过文档链接接口 public static Boolean ContentDocumentLink = true; public StaticParameter(){ } force-app/main/default/lwc/lexNewAgencyHospital/lexNewAgencyHospital.js
@@ -1,3 +1,11 @@ /* * @Description: * @version: * @Author: chen jing wu * @Date: 2023-06-15 09:52:50 * @LastEditors: chen jing wu * @LastEditTime: 2023-07-25 09:16:27 */ import { api, wire,LightningElement } from 'lwc'; import { CurrentPageReference } from "lightning/navigation"; import { CloseActionScreenEvent } from 'lightning/actions'; @@ -6,7 +14,7 @@ import { NavigationMixin } from 'lightning/navigation'; import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils'; export default class LexNewAgencyHospital extends LightningElement { export default class LexNewAgencyHospital extends NavigationMixin(LightningElement) { @wire(CurrentPageReference) getStateParameters(currentPageReference) { console.log(111); force-app/main/default/pages/DiscountProductApplication.page
@@ -1,4 +1,4 @@ <apex:page standardController="DiscountProductApplication__c" extensions="DiscountProductApplicationController" action="{!init}" showHeader="false" sidebar="true" id="dpaPage" title="特价产品申请信息"> <apex:page standardController="DiscountProductApplication__c" extensions="DiscountProductApplicationController" action="{!init}" showHeader="false" sidebar="true" id="dpaPage" title="特价产品申请信息" lightningStylesheets="true"> <apex:stylesheet value="{!URLFOR($Resource.blockUIcss)}"/> <apex:includeScript value="{!URLFOR($Resource.jquery183minjs)}"/> <apex:includeScript value="{!URLFOR($Resource.PleaseWaitDialog)}"/> @@ -109,7 +109,7 @@ <apex:actionFunction name="search" action="{!searchAllProduct2}" oncomplete="unblockUI();" reRender="ConsumableorderdetailsSection,message" /> <apex:pageBlock title="特价产品申请信息" id="dpaBlock" > <apex:pageBlockButtons location="top" > <apex:commandButton value="保存" disabled="{!IF(dpa.ApplicationStatus__c='申请中'||dpa.ApplicationStatus__c='批准'||dpa.ApplicationStatus__c='驳回',true,false)}" onclick="blockme();" style="margin-left:30px;width:100px" action="{!savesaveDiscountProduct}" onComplete="unblockUI();CheckStatusAfter();" reRender="ConsumableorderdetailsSection,message"/> <apex:commandButton value="保存" disabled="{!IF(dpa.ApplicationStatus__c='申请中'||dpa.ApplicationStatus__c='批准'||dpa.ApplicationStatus__c='驳回',true,false)}" onclick="blockme();" style="margin-left:30px;width:100px;float: left;" action="{!savesaveDiscountProduct}" onComplete="unblockUI();CheckStatusAfter();" reRender="ConsumableorderdetailsSection,message"/> </apex:pageBlockButtons> <table style="width: 900px;margin: auto;"> <tr> force-app/main/default/pages/MaintenanceProductData.page
@@ -21,6 +21,17 @@ td.dataCol.first.last{ width: 100% } body .pbBody table.list tr th, body .pbBody table.list tr td { border: 1px solid #ededed; white-space: nowrap; } body .pbBody table.list tr.headerRow td,body .pbBody table.list tr.headerRow th { background: #f2f3f3; border-width: 0 0 1px 1px; border-color: #e0e3e5; font-size: .9em; font-weight: bold; } </style> <script> function refreshPageSizeJs() { @@ -957,9 +968,9 @@ <div style="float: left;width: 95%;overflow:auto;"> <table class="list" border="0" cellpadding="0" cellspacing="0" width="100%" > <tr class="headerRow"> <th rowspan = "2">未选择的产品<br/>选中数据批量修改</th> <th rowspan = "2" style="min-width: 100px">未选择的产品<br/>选中数据批量修改</th> <apex:repeat value="{!title}" var="t"> <th><apex:outputText value="{!t}"/></th> <th style="min-width: 100px"><apex:outputText value="{!t}"/></th> </apex:repeat> </tr> <!-- 重点产品维护 --> @@ -1157,7 +1168,7 @@ </table> </div> <div style="float: right;width:4%;position:relative;" > <button type="button" onclick="moreChange();" style="width:100%;display:inline-block;height:30px;margin-top:15px;">确定</button> <button type="button" onclick="moreChange();" style="width: 100%;display: inline-block;height: 30px;margin-top: 30px;border-radius: .25rem;color: rgba(1, 118, 211, 1);background-color: white;border-width: 1px;border-color: rgb(201, 201, 201);border-style: double;">确定</button> </div> <div style="clear: both;"></div> </apex:pageBlock> @@ -1199,7 +1210,7 @@ </table> </div> <div style="float: right;width:4%;position:relative;" > <button type="button" onclick="ServiceMoreChange();" style="width:100%;display:inline-block;height:30px;margin-top:15px;">确定</button> <button type="button" onclick="ServiceMoreChange();" style="width: 100%;display: inline-block;height: 30px;margin-top: 30px;border-radius: .25rem;color: rgba(1, 118, 211, 1);background-color: white;border-width: 1px;border-color: rgb(201, 201, 201);border-style: double;">确定</button> </div> <div style="clear: both;"></div> </apex:pageBlock> @@ -1215,21 +1226,38 @@ <input type="hidden" id="allPage:allForm:allBlock:edmpdDetails:mpdDetailsRecordsCount" value="{!mpdDetailsRecordsCount}" /> <table class="list" border="0" cellpadding="0" cellspacing="0"> <tr class="headerRow"> <apex:variable var="v" value="" rendered="{!IF(editAble&&RecordTypeName='GuranteeMain'&&mpd.Status__c='服务填写',true,false)}"> <th>选择</th> <apex:variable var="q" value="" rendered="{!IF(editAble,true,false)}"> <apex:variable var="v" value="" rendered="{!IF(editAble&&RecordTypeName='GuranteeMain'&&mpd.Status__c='服务填写',true,false)}"> <th>选择</th> </apex:variable> <th>产品名称</th> <th>产品编码</th> <apex:variable var="type" value="" rendered="{!IF(RecordTypeName='GuranteePrice',true,false)}"> <th>多年保修类型</th> </apex:variable> <apex:repeat value="{!title}" var="t"> <th><apex:outputText value="{!t}"/></th> </apex:repeat> <apex:variable var="type" value="" rendered="{!IF(editAble&&!(RecordTypeName='GuranteeMain'&&mpd.Status__c='服务填写'),true,false)}"> <th>操作</th> </apex:variable> </apex:variable> <th>产品名称</th> <th>产品编码</th> <apex:variable var="type" value="" rendered="{!IF(RecordTypeName='GuranteePrice',true,false)}"> <th>多年保修类型</th> </apex:variable> <apex:repeat value="{!title}" var="t"> <th><apex:outputText value="{!t}"/></th> </apex:repeat> <apex:variable var="type" value="" rendered="{!IF(editAble&&!(RecordTypeName='GuranteeMain'&&mpd.Status__c='服务填写'),true,false)}"> <th>操作</th> <apex:variable var="q" value="" rendered="{!IF(editAble,false,true)}"> <apex:variable var="v" value="" rendered="{!IF(editAble&&RecordTypeName='GuranteeMain'&&mpd.Status__c='服务填写',true,false)}"> <th>选择</th> </apex:variable> <th style="min-width: 130px;">产品名称</th> <th style="min-width: 130px;">产品编码</th> <apex:variable var="type" value="" rendered="{!IF(RecordTypeName='GuranteePrice',true,false)}"> <th>多年保修类型</th> </apex:variable> <apex:repeat value="{!title}" var="t"> <th style="min-width: 130px;"><apex:outputText value="{!t}"/></th> </apex:repeat> <apex:variable var="type" value="" rendered="{!IF(editAble&&!(RecordTypeName='GuranteeMain'&&mpd.Status__c='服务填写'),true,false)}"> <th>操作</th> </apex:variable> </apex:variable> </tr> <apex:repeat value="{!mpdDetailsRecords}" var="aa" id="bb"> <tr> force-app/main/default/pages/MaintenanceProductDataManage.page
@@ -1,10 +1,14 @@ <apex:page standardController="Maintenance_Product_Data__c" showHeader="false" sidebar="false"> <apex:page standardController="Maintenance_Product_Data__c" showHeader="true" sidebar="true" lightningStylesheets="true"> <script type="text/javascript"> function init() { // var test = window.location.search; var str = '/apex/MaintenanceProductData?cpn1=*'; console.log("123124215125"); if(getParam('RecordType') != null){ str += '&RecordType='+getParam('RecordType'); } if(getParam('recordTypeId') != null){ str += '&RecordType='+getParam('recordTypeId'); } if(getParam('CMRT') != null){ str += '&CMRT='+getParam('CMRT'); @@ -30,12 +34,16 @@ } function getParam(paramName) { paramValue = "", isFound = !1; console.log(this.location.search); if (this.location.search.indexOf("?") == 0 && this.location.search.indexOf("=") > 1) { arrSource = unescape(this.location.search).substring(1, this.location.search.length).split("&"), i = 0; while (i < arrSource.length && !isFound) arrSource[i].indexOf("=") > 0 && arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase() && (paramValue = arrSource[i].split("=")[1], isFound = !0), i++ } return paramValue == "" && (paramValue = null), paramValue } document.addEventListener("DOMContentLoaded", function(event) { init(); }); </script> <body onload="init()"> force-app/main/default/pages/SubAuthorizedCreate.page
@@ -24,6 +24,9 @@ } return paramValue == "" && (paramValue = null), paramValue } document.addEventListener("DOMContentLoaded", function(event) { init(); }); </script> <body onload="init()"> </body> force-app/main/default/triggers/ContentDocumentLink.trigger
New file @@ -0,0 +1,75 @@ trigger ContentDocumentLink on ContentDocumentLink (before delete, after insert) { // if((!Test.isRunningTest())&&UserInfo.getUserId()==System.Label.ByPassTrigger){ // return; // } system.debug('enter ContentDocumentLink'); system.debug('Trigger.new = ' + (List<ContentDocumentLink>) Trigger.new); system.debug('Trigger.old = ' + (List<ContentDocumentLink>) Trigger.old); String invoiceStart = System.Label.invoiceStart; System.debug('invoiceStart = ' + invoiceStart); List<String> rentalIds = new List<String>(); List<String> attIds = new List<String>(); // List<String> rentaldelIds = new List<String>(); // List<String> attdelIds = new List<String>(); if (Trigger.isAfter && Trigger.isInsert) { System.debug('Trigger.isAfter && Trigger.isInsert'); for (ContentDocumentLink cdl : Trigger.new) { System.debug('cdl.LinkedEntityId = ' + cdl.LinkedEntityId); System.debug('cdl.ContentDocumentId = ' + cdl.ContentDocumentId); if (String.valueOf(cdl.LinkedEntityId).startsWith(invoiceStart)) { System.debug('String.valueOf(cdl.LinkedEntityId).startsWith(invoiceStart)'); rentalIds.add(cdl.LinkedEntityId); attIds.add(cdl.ContentDocumentId); System.debug('rentalIds = ' + rentalIds); System.debug('attIds = ' + attIds); } } } // if (Trigger.isBefore && Trigger.isDelete) { // System.debug('Trigger.isBefore && Trigger.isDelete'); // for (ContentDocumentLink cdl : Trigger.old) { // System.debug('cdl.LinkedEntityId = ' + cdl.LinkedEntityId); // System.debug('cdl.ContentDocumentId = ' + cdl.ContentDocumentId); // if (String.valueOf(cdl.LinkedEntityId).startsWith(invoiceStart)) { // System.debug('String.valueOf(cdl.LinkedEntityId).startsWith(invoiceStart)'); // rentaldelIds.add(cdl.LinkedEntityId); // attdelIds.add(cdl.ContentDocumentId); // System.debug('rentaldelIds = ' + rentaldelIds); // System.debug('attdelIds = ' + attdelIds); // } // } // } if (rentalIds.size() > 0) { List<Consumable_order__c> rentalList = new List<Consumable_order__c>(); for (Consumable_order__c ra : [SELECT Id FROM Consumable_order__c WHERE Id IN :rentalIds]) { ra.Consumable_pdf_insert_day__c = Date.today(); ra.Order_Attachment__c = attIds[0]; rentalList.add(ra); } System.debug('rentalList = ' + rentalList); ControllerUtil.updRentalApplyList(rentalList); } // if (Trigger.isInsert && Trigger.isAfter && StaticParameter.ContentDocumentLink) { // AttachmentReQisHandler handler = new AttachmentReQisHandler(); // handler.run(); // } // if (rentaldelIds.size() > 0) { // List<Consumable_accessories_invoice__c> rentaldelList = new List<Consumable_accessories_invoice__c>(); // for (Consumable_accessories_invoice__c ra : [ // SELECT Id // FROM Consumable_accessories_invoice__c // WHERE Invoice_code__c IN :rentaldelIds AND Attachment_ID__c IN :attdelIds // ]) { // rentaldelList.add(ra); // } // System.debug('rentaldelList = ' + rentaldelList); // ControllerUtil.delConsumableAccessoriesInvoiceSet(rentaldelList); // } } force-app/main/default/triggers/ContentDocumentLink.trigger-meta.xml
New file @@ -0,0 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> <ApexTrigger xmlns="http://soap.sforce.com/2006/04/metadata"> <apiVersion>57.0</apiVersion> <status>Active</status> </ApexTrigger>