function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MargiroMargiro 

Blank pdf attachment

I have written the code for an email template that is used by a trigger. The template is supposed to render a bunch of information from the VF into a pdf. This works in the email template preview but not when the vf page is completed. I believe it has to do with recipientType or relatedToType but neither of them work. Also can I get the setobjectId to generate the lead id when the email sets insted of having it as a non variable.  How do I link the information on the VF page to the PDF file?

 

Template Code

 

<messaging:emailTemplate subject="Conveyor Form Entered" recipientType="lead"> <messaging:htmlEmailBody > A new order has been entered for a conveyor. </messaging:htmlEmailBody> <messaging:attachment renderAs="pdf" filename="{!recipient.company}" > <br><b>Lead ID:</b>{!recipient.id}</br> <br></br> <br><u><b>Contact Information</b></u></br> <br><b>Name:</b>{!recipient.firstname} {!recipient.lastname}</br> <br><b>Email:</b>{!recipient.email}</br> <br><b>Company:</b>{!recipient.company}</br> <br><b>Website:</b>{!recipient.website}</br> <br><b>Title:</b>{!recipient.title}</br> <br><b>Phone/Fax:</b>{!recipient.phone}/{!recipient.fax}</br> <br><b>Address:</b><ADDRESS>{!recipient.street}</br> <br>{!recipient.city},{!recipient.state}</br> <br>{!recipient.postalcode} {!recipient.country}</br></ADDRESS> <br><u><b>Product Information</b></u></br> <br><b>Product Conveyed:</b>{!recipient.Product_conveyed__c}</br> <br><b>Bulk Density:</b>{!recipient.Bulk_density__c}{!recipient.Bulk_Density_Units__c}</br> <br><b>Particle Size:</b>{!recipient.Particle_size__c}{!recipient.Particle_Size_Units__c}</br> <br><b>Angle of Repose:</b>{!recipient.Angle_of_repose__c}</br> <br><b>Flow:</b>{!recipient.Flow__c}</br> <br><b>Hazards:</b>{!recipient.Hazards__c}</br> <br><b>Other Properties:</b>{!recipient.Other_product_properties__c}</br> <br></br> <br><u><b>Installation Information</b></u></br> <br><b>Capacity:</b>{!recipient.Capacity__c}{!recipient.Capacity_Units__c}</br> <br><b>Total Conveying Distance:</b>{!recipient.Total_conveying_distance__c}{!recipient.Total_Conveying_Distance_Units__c}</br> <br><b>Horizontal:</b>{!recipient.Horizontal__c}{!recipient.Horizontal_Units__c}</br> <br><b>Vertical:</b>{!recipient.Vertical__c}{!recipient.Vertical_Units__c}</br> <br><b>Max Headroom:</b>{!recipient.Max_Headroom__c}{!recipient.Max_Headroom_Units__c}</br> <br><b>Number of Bends:</b>{!recipient.Number_of_bends__c}</br> <br><b>Type of Pipe System:</b>{!recipient.Type_of_pipe_system__c}</br> <br><b>Product Picked Up From:</b>{!recipient.Product_picked_up_from__c}</br> <br><b>Other Pick Up:</b>{!recipient.If_Others__c}</br> <br><b>Product Discharged To:</b>{!recipient.Product_Discharge__c}</br> <br><b>Other Discharge:</b>{!recipient.If_Others2__c}</br> <br><b>Installation is:</b>{!recipient.The_installation_is__c}</br> <br><b>The Operation is:</b>{!recipient.The_operation_is__c}</br> <br><b>Project Timeline:</b>{!recipient.Project_Timeline__c}</br> <br><b>Other Information:</b>{!recipient.Other_information__c}</br> </messaging:attachment> </messaging:emailTemplate>

 Trigger Code

 

trigger mhform on Lead (after insert) { Messaging.SingleEmailMessage mail= new Messaging.SingleEmailMessage(); String[] toAddresses = new String[]{'margiro@piab.com'}; mail.setToAddresses(toAddresses); mail.setTemplateId('00X400000016by4'); mail.settargetObjectId(!relatedTo.lead.id); mail.setReplyTo('support@acme.com'); mail.setSenderDisplayName('Piab Support'); mail.setSaveAsActivity(false); mail.setBccSender(false); mail.setUseSignature(false); Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail}); }