// before update のみ対応した
|
trigger TemporaryFileBoxUpdate on TemporaryFileBox__c (before update) {
|
|
//deloitte-zhj 20231124 本地化导入 start
|
if((!Test.isRunningTest())&&System.Label.ByPassTrigger.contains(UserInfo.getUserId())){
|
return;
|
}
|
//deloitte-zhj 20231124 本地化导入 end
|
|
List<Id> tfbIds = new List<Id>();
|
for(TemporaryFileBox__c tfb : Trigger.new) {
|
if (tfb.Status__c == '已申请' || tfb.Status__c == '已批准') {
|
tfbIds.add(tfb.Id);
|
}
|
}
|
if (tfbIds.size() > 0) {
|
//20231026 于梦辉 附件修改 start
|
// 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
|
// ]);
|
|
Map<Id, AggregateResult> arMap = new Map<Id, AggregateResult>(
|
[SELECT LinkedEntityId Id, Count(ContentDocumentId) Cnt_Id
|
FROM ContentDocumentLink
|
WHERE LinkedEntityId IN :tfbIds
|
GROUP BY LinkedEntityId
|
]);
|
//20231026 于梦辉 附件修改 end
|
|
for(TemporaryFileBox__c tfb : Trigger.new) {
|
AggregateResult ar = arMap.get(tfb.Id);
|
if (ar == null || Integer.valueOf(ar.get('Cnt_Id')) == 0) {
|
tfb.addError(System.Label.TemporaryFileBoxNeedAttachment);
|
}
|
}
|
}
|
}
|