Untitled
unknown
plain_text
5 months ago
3.0 kB
7
Indexable
system.debug('I am inside sendPdfEmail'); // Generate the PDF as an attachment PageReference pdfPage = Page.Inv_QuoteGeneratePDF; pdfPage.getParameters().put('id', workOrder.Id); Blob pdfBlob = pdfPage.getContentAsPDF(); system.debug(pdfBlob); // Set the email details Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); //mail.setToAddresses(new String[] {'mohim@inovisolutions.com'}); mail.setToAddresses(new String[] {workOrder.Contact.Email}); mail.setSubject('Your Quotation PDF'); mail.setPlainTextBody('Please find your quotation attached as a PDF.'); // Retrieve the Organization-Wide Email Address ID List<OrgWideEmailAddress> orgWideEmail = [SELECT Id FROM OrgWideEmailAddress WHERE Address = 'hardwareservices@angiodynamics.com' LIMIT 1]; if (!orgWideEmail.isEmpty()) { //mail.setOrgWideEmailAddressId(orgWideEmail[0].Id); } else { System.debug('No Org-Wide Email Address found.'); } // Create the email attachment Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment(); attachment.setBody(pdfBlob); attachment.setContentType('application/pdf'); mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attachment }); // Send the email Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM, 'Email sent successfully with the PDF attachment.')); // Step 1: Create a new ContentVersion ContentVersion contentVersion = new ContentVersion(); contentVersion.VersionData = pdfBlob; contentVersion.Title = 'quotation.pdf'; contentVersion.PathOnClient = '/' + 'quotation.pdf'; insert contentVersion; // Step 2: Query the ContentDocumentId from the ContentVersion ContentVersion insertedContentVersion = [SELECT Id, ContentDocumentId,VersionDataUrl,Title FROM ContentVersion WHERE Id = :contentVersion.Id]; // Step 3: Create a ContentDocumentLink to associate the ContentDocument with the PaymentSummary record ContentDocumentLink contentDocumentLink = new ContentDocumentLink(); contentDocumentLink.ContentDocumentId = insertedContentVersion.ContentDocumentId; contentDocumentLink.LinkedEntityId = workOrder.id; contentDocumentLink.ShareType = 'V'; // View Only contentDocumentLink.Visibility = 'AllUsers'; insert contentDocumentLink;
Editor is loading...
Leave a Comment