From 75550e1bd16611d11ffac577f14ba743c6711338 Mon Sep 17 00:00:00 2001
From: yumenghui <953181891@qq.com>
Date: 星期一, 07 八月 2023 20:33:22 +0800
Subject: [PATCH] 按钮及附件修改
---
force-app/main/default/classes/QISToETQWebService.cls | 53 +++++++++++++++++++++++++++++++++++++++--------------
1 files changed, 39 insertions(+), 14 deletions(-)
diff --git a/force-app/main/default/classes/QISToETQWebService.cls b/force-app/main/default/classes/QISToETQWebService.cls
index bcba6d8..1d86c90 100644
--- a/force-app/main/default/classes/QISToETQWebService.cls
+++ b/force-app/main/default/classes/QISToETQWebService.cls
@@ -20,7 +20,8 @@
apiNames.add('Photo_OSH_3__c');
apiNames.add('Photo_OSH_4__c');
List<QIS_Report__c> updateQis = new List<QIS_Report__c>();
- List<Attachment> attachments = new List<Attachment>();
+ // List<Attachment> attachments = new List<Attachment>();
+ List<ContentDocumentLink> attachments = new List<ContentDocumentLink>();
PageReference pdfPage ;
for(QIS_Report__c qis : temp){
for (String apiName : apiNames) {
@@ -39,16 +40,27 @@
} else {
pdfBody = pdfPage.getContentAsPDF();
}
- Attachment attach = new Attachment();
- attach.Body = pdfBody;
+ // Attachment attach = new Attachment();
+ // attach.Body = pdfBody;
+ ContentVersion cv = new ContentVersion();
+ cv.VersionData = pdfBody;
if ('problem_detail_photo__c'.equals(apiName)) {
- attach.Name = substringApiName(qis.name) + '_Problem_Discription.pdf';
+ // attach.Name = substringApiName(qis.name) + '_Problem_Discription.pdf';
+ cv.Title = substringApiName(qis.name) + '_Problem_Discription.pdf';
}else {
- attach.Name = substringApiName(qis.name) + '_' + 'Problem_' + apiName.substring(0,apiName.length()-3) + '.pdf';
+ // attach.Name = substringApiName(qis.name) + '_' + 'Problem_' + apiName.substring(0,apiName.length()-3) + '.pdf';
+ cv.Title = substringApiName(qis.name) + '_' + 'Problem_' + apiName.substring(0,apiName.length()-3) + '.pdf';
}
- attach.ParentId = qis.id;
-
- attachments.add(attach);
+ // attach.ParentId = qis.id;
+ insert cv;
+ Id docId = [SELECT ContentDocumentId FROM ContentVersion WHERE Id = :cv.Id].ContentDocumentId;
+ ContentDocumentLink cdl = new ContentDocumentLink();
+ cdl.ContentDocumentId = docId;
+ cdl.LinkedEntityId = qis.id;
+ cdl.ShareType = 'I';
+ cdl.visibility = 'AllUser';
+ // attachments.add(attach);
+ attachments.add(cdl);
if (generatedFields == null) {
qis.GeneratedPDFField__c = apiName;
}else {
@@ -90,7 +102,8 @@
PageReference pdfPage ;
List<Repair__c> updateRpr = new List<Repair__c>();
- List<Attachment> attachments = new List<Attachment>();
+ // List<Attachment> attachments = new List<Attachment>();
+ List<ContentDocumentLink> attachments = new List<ContentDocumentLink>();
for(Repair__c re : tempRe){
String generatedFields = re.GeneratedPDFField__c;
if (checkFieldisGeneratedPDF('ProblemDescription__c',re)) {
@@ -108,11 +121,23 @@
} else {
pdfBody = pdfPage.getContentAsPDF();
}
- Attachment attach = new Attachment();
- attach.Body = pdfBody;
- attach.Name = re.name + '_' + 'Problem_Discription.pdf';
- attach.ParentId = re.id;
- attachments.add(attach);
+ // Attachment attach = new Attachment();
+ // attach.Body = pdfBody;
+ // attach.Name = re.name + '_' + 'Problem_Discription.pdf';
+ // attach.ParentId = re.id;
+ ContentVersion cv = new ContentVersion();
+ cv.VersionData = pdfBody;
+ cv.Title = re.name + '_' + 'Problem_Discription.pdf';
+ insert cv;
+ Id docId = [SELECT ContentDocumentId FROM ContentVersion WHERE Id = :cv.Id].ContentDocumentId;
+ ContentDocumentLink cdl = new ContentDocumentLink();
+ cdl.ContentDocumentId = docId;
+ cdl.LinkedEntityId = re.id;
+ cdl.ShareType = 'I';
+ cdl.visibility = 'AllUser';
+
+ // attachments.add(attach);
+ attachments.add(cdl);
re.GeneratedPDFField__c = 'ProblemDescription__c';
updateRpr.add(re);
}
--
Gitblit v1.9.1