| | |
| | | PageReference pdfPage ; |
| | | |
| | | List<Repair__c> updateRpr = new List<Repair__c>(); |
| | | List<Attachment> attachments = new List<Attachment>(); |
| | | // List<Attachment> attachments = new List<Attachment>(); |
| | | List<ContentVersion> cVersions = new List<ContentVersion>(); |
| | | List<ContentDocumentLink> cDocLinks = new List<ContentDocumentLink>(); |
| | | Map<String,String> res = new Map<String, String>(); |
| | | for(Repair__c re : repList){ |
| | | String generatedFields = re.GeneratedPDFField__c; |
| | | if (checkFieldisGeneratedPDF('ProblemDescription__c',re)) { |
| | |
| | | } 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); |
| | | ContentVersion version = new ContentVersion(); |
| | | version.VersionData = pdfBody; |
| | | version.Title = re.name + '_' + 'Problem_Discription.pdf'; |
| | | version.PathOnClient = re.name + '_' + 'Problem_Discription.pdf'+'.pdf'; |
| | | cVersions.add(version); |
| | | res.put(version.Title, re.Id); |
| | | // insert version; |
| | | // Attachment attach = new Attachment(); |
| | | // attach.Body = pdfBody; |
| | | // attach.Name = re.name + '_' + 'Problem_Discription.pdf'; |
| | | // attach.ParentId = re.id; |
| | | // attachments.add(attach); |
| | | re.GeneratedPDFField__c = 'ProblemDescription__c'; |
| | | updateRpr.add(re); |
| | | } |
| | | insert attachments; |
| | | if (cVersions.size()>0) { |
| | | insert cVersions; |
| | | } |
| | | List<Id> idList = new List<Id>(); |
| | | for (ContentVersion newVersion : cVersions) { |
| | | idList.add(newVersion.Id); |
| | | } |
| | | cVersions = [select ContentDocumentId,Title from ContentVersion where Id in: idList]; |
| | | for (ContentVersion cv : cVersions) { |
| | | ContentDocumentLink cdl = new ContentDocumentLink(); |
| | | cdl.ContentDocumentId = cv.ContentDocumentId; |
| | | cdl.LinkedEntityId = res.get(cv.Title); |
| | | cdl.ShareType = 'I'; |
| | | cdl.visibility = 'AllUser'; |
| | | cDocLinks.add(cdl); |
| | | } |
| | | insert cDocLinks; |
| | | // insert attachments; |
| | | update updateRpr; |
| | | return null; |
| | | } |
| | |
| | | System.debug('1111111111111111111111111111111111111111111111111generateAttachment执行了-----------'); |
| | | |
| | | List<QIS_Report__c> updateQis = new List<QIS_Report__c>(); |
| | | List<Attachment> attachments = new List<Attachment>(); |
| | | // List<Attachment> attachments = new List<Attachment>(); |
| | | List<ContentVersion> cVersions = new List<ContentVersion>(); |
| | | List<ContentDocumentLink> cDocLinks = new List<ContentDocumentLink>(); |
| | | Map<String,String> res = new Map<String, String>(); |
| | | PageReference pdfPage ; |
| | | for(QIS_Report__c qis : qisReports){ |
| | | |
| | |
| | | } else { |
| | | pdfBody = pdfPage.getContentAsPDF(); |
| | | } |
| | | Attachment attach = new Attachment(); |
| | | attach.Body = pdfBody; |
| | | ContentVersion version = new ContentVersion(); |
| | | version.VersionData = pdfBody; |
| | | // Attachment attach = new Attachment(); |
| | | // attach.Body = pdfBody; |
| | | if ('problem_detail_photo__c'.equals(apiName)) { |
| | | attach.Name = substringApiName(qis.name) + '_Problem_Discription.pdf'; |
| | | // attach.Name = substringApiName(qis.name) + '_Problem_Discription.pdf'; |
| | | version.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'; |
| | | version.Title = substringApiName(qis.name) + '_' + 'Problem_' + apiName.substring(0,apiName.length()-3) + '.pdf'; |
| | | } |
| | | attach.ParentId = qis.id; |
| | | |
| | | attachments.add(attach); |
| | | version.PathOnClient = substringApiName(qis.name) + '_' + 'Problem_' + apiName.substring(0,apiName.length()-3) + '.pdf'+'.pdf'; |
| | | // attach.ParentId = qis.id; |
| | | // attachments.add(attach); |
| | | cVersions.add(version); |
| | | res.put(version.Title, qis.Id); |
| | | // insert version; |
| | | if (generatedFields == null) { |
| | | qis.GeneratedPDFField__c = apiName; |
| | | }else { |
| | |
| | | } |
| | | updateQis.add(qis); |
| | | } |
| | | insert attachments; |
| | | if (cVersions.size()>0) { |
| | | insert cVersions; |
| | | } |
| | | List<Id> idList = new List<Id>(); |
| | | for (ContentVersion newVersion : cVersions) { |
| | | idList.add(newVersion.Id); |
| | | } |
| | | cVersions = [select ContentDocumentId,Title from ContentVersion where Id in: idList]; |
| | | for (ContentVersion cv : cVersions) { |
| | | ContentDocumentLink cdl = new ContentDocumentLink(); |
| | | cdl.ContentDocumentId = cv.ContentDocumentId; |
| | | cdl.LinkedEntityId = res.get(cv.Title); |
| | | cdl.ShareType = 'I'; |
| | | cdl.visibility = 'AllUsers'; |
| | | cDocLinks.add(cdl); |
| | | } |
| | | insert cDocLinks; |
| | | // insert attachments; |
| | | update updateQis; |
| | | |
| | | return null; |