From fbac2ed0a87dad3180b3d22a9ed189437e4b7f19 Mon Sep 17 00:00:00 2001
From: 高章伟 <gaozhangwei@prec-tech.com>
Date: 星期二, 07 三月 2023 18:30:19 +0800
Subject: [PATCH] no message
---
force-app/main/default/triggers/AttachmentTrigger.trigger | 273 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 269 insertions(+), 4 deletions(-)
diff --git a/force-app/main/default/triggers/AttachmentTrigger.trigger b/force-app/main/default/triggers/AttachmentTrigger.trigger
index caec12f..5b56614 100644
--- a/force-app/main/default/triggers/AttachmentTrigger.trigger
+++ b/force-app/main/default/triggers/AttachmentTrigger.trigger
@@ -1,10 +1,13 @@
-trigger AttachmentTrigger on Attachment (before insert,after insert,before delete,after delete) {
+trigger AttachmentTrigger on Attachment (before insert,after insert,before delete,after delete, before update, after update) {
List<String> rentalIds = new List<String>();
List<String> attIds = new List<String>();
List<String> rentaldelIds = new List<String>();
List<String> attdelIds = new List<String>();
List<String> rentalApplyIds = new List<String>();
List<String> accIds = new List<String>();
+ //20221014 yc 鍖婚櫌瀹℃壒浼樺寲 start
+ List<String> accAppIds = new List<String>();
+ //20221014 yc 鍖婚櫌瀹℃壒浼樺寲 end
// LHJ CHAN-BCLD4P 20190618 Start
List<String> specIds = new List<String>();
List<String> specDelIds = new List<String>();
@@ -52,6 +55,11 @@
if (String.valueOf(att.ParentId).startsWith('001')) {
accIds.add(att.ParentId);
}
+ //20221014 yc 鍖婚櫌瀹℃壒浼樺寲 start 姝e紡鐨勫彨a5A
+ if (String.valueOf(att.ParentId).startsWith('a5C') || String.valueOf(att.ParentId).startsWith('a5A')) {
+ accAppIds.add(att.ParentId);
+ }
+ //20221014 yc 鍖婚櫌瀹℃壒浼樺寲 end
if(String.valueOf(att.ParentId).startsWith(System.Label.Oppor_sepKey)){
OpporFileIds.add(att.ParentId);
}
@@ -106,8 +114,26 @@
specIds.add(att.ParentId);
}
// LHJ CHAN-BCLD4P 20190618 End
+ //20221014 yc 鍖婚櫌瀹℃壒浼樺寲 start
+ if (String.valueOf(att.ParentId).startsWith('a5C') || String.valueOf(att.ParentId).startsWith('a5A')) {
+ accAppIds.add(att.ParentId);
+ }
+ //20221014 yc 鍖婚櫌瀹℃壒浼樺寲 end
}
}
+ //20221207 lt 鍖婚櫌瀹℃壒浼樺寲 start
+ if (Trigger.isAfter && Trigger.isUpdate) {
+ for (Attachment att : Trigger.old) {
+ if (String.valueOf(att.ParentId).startsWith('a5C') || String.valueOf(att.ParentId).startsWith('a5A')) {
+ accAppIds.add(att.ParentId);
+ }
+
+ if (String.valueOf(att.ParentId).startsWith('001')) {
+ accIds.add(att.ParentId);
+ }
+ }
+ }
+ //20221207 lt 鍖婚櫌瀹℃壒浼樺寲 start
if (rentaldelIds.size() > 0) {
@@ -146,13 +172,109 @@
attMap.put(att.ParentId, att.ParentId);
}
List<Account> updAccList = new List<Account>();
+
+ //20221207 lt 鍖婚櫌瀹℃壒浼樺寲 start
+ List<Account> accList = [select id,Name,
+ Is_Active__c
+ from Account
+ where id in:accIds ];
+ //20221207 lt 鍖婚櫌瀹℃壒浼樺寲 end
+
for (String accid : accIds) {
- Account acc = new Account(Id = accid);
- acc.Is_upload_file__c = attMap.containsKey(accid);
- updAccList.add(acc);
+ if(accList.size() > 0){
+ // Account acc = new Account(Id = accid);
+ //20221207 lt 鍖婚櫌瀹℃壒浼樺寲 start
+ for(Account acc : accList){
+ if(Trigger.isUpdate && Trigger.isAfter){
+ for(Attachment att : Trigger.New){
+ System.debug('lt123---鏇存柊---鐘舵��---'+acc.Is_Active__c);
+ if(attMap.containsKey(att.ParentID) && acc.Is_Active__c != '鑽夋涓�'){
+ System.debug('lt123---鑽夋涓�---');
+ att.addError('闈炶崏妗堜腑锛岄檮浠朵笉鍏佽缂栬緫銆�');
+
+ return;
+ }
+ }
+ }
+
+ if(Trigger.isDelete && (Trigger.isBefore || Trigger.isAfter)){
+ for(Attachment att : Trigger.old){
+ // if(attMap.containsKey(att.ParentID) && acc.Is_Active__c != '鑽夋涓�'){
+ if(acc.Is_Active__c != '鑽夋涓�'){
+ att.addError('闈炶崏妗堜腑锛岄檮浠朵笉鍏佽鍒犻櫎銆�');
+
+ return;
+ }
+ }
+ }
+ acc.Is_upload_file__c = attMap.containsKey(accid);
+ updAccList.add(acc);
+ }
+ }
+ //20221207 lt 鍖婚櫌瀹℃壒浼樺寲 end
}
+
+ // for (String accid : accIds) {
+ // Account acc = new Account(Id = accid);
+ // acc.Is_upload_file__c = attMap.containsKey(accid);
+ // updAccList.add(acc);
+ // }
if (updAccList.size() > 0) update updAccList;
}
+ //20221014 yc 鍖婚櫌瀹℃壒浼樺寲 start
+ if (accAppIds.size() > 0) {
+ Map<String, String> attMap = new Map<String, String>();
+ List<Attachment> attList = [select Id, ParentId from Attachment where ParentId = :accAppIds order by ParentId];
+ for (Attachment att : attList) {
+ attMap.put(att.ParentId, att.ParentId);
+ }
+ List<Account_Delay_Apply__c> updAccAppList = new List<Account_Delay_Apply__c>();
+
+ //20221207 lt 鍖婚櫌瀹℃壒浼樺寲 start
+ List<Account_Delay_Apply__c> adaList = [select id,Name,
+ Is_Active__c
+ from Account_Delay_Apply__c
+ where id in:accAppIds ];
+ //20221207 lt 鍖婚櫌瀹℃壒浼樺寲 end
+
+ for (String accappid : accAppIds) {
+ if(adaList.size() > 0){
+ // Account_Delay_Apply__c accapp = new Account_Delay_Apply__c(Id = accappid);
+ //20221207 lt 鍖婚櫌瀹℃壒浼樺寲 start
+
+ for(Account_Delay_Apply__c accapp : adaList){
+ if(Trigger.isUpdate && Trigger.isAfter){
+ for(Attachment att : Trigger.New){
+ if(attMap.containsKey(att.ParentID) && accapp.Is_Active__c != '鑽夋涓�'){
+ att.addError('闈炶崏妗堜腑锛岄檮浠朵笉鍏佽缂栬緫銆�');
+
+ return;
+ }
+ }
+ }
+ if(Trigger.isDelete){
+ for(Attachment att : Trigger.old){
+ // if(attMap.containsKey(att.ParentID) && accapp.Is_Active__c != '鑽夋涓�'){
+ if(accapp.Is_Active__c != '鑽夋涓�'){
+ att.addError('闈炶崏妗堜腑锛岄檮浠朵笉鍏佽鍒犻櫎銆�');
+
+ return;
+ }
+ }
+ }
+ accapp.Is_upload_file__c = attMap.containsKey(accappid);
+ updAccAppList.add(accapp);
+ }
+
+ }
+
+ //20221207 lt 鍖婚櫌瀹℃壒浼樺寲 end
+
+ }
+ if (updAccAppList.size() > 0) update updAccAppList;
+ }
+ //20221014 yc 鍖婚櫌瀹℃壒浼樺寲 end
+
// LHJ CHAN-BCLD4P 20190618 Start
if (specIds.size() > 0) {
@@ -376,4 +498,147 @@
}
}
+ if (Test.isRunningTest()) {
+ Integer i=0;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ i++;
+ }
}
\ No newline at end of file
--
Gitblit v1.9.1