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
Paul.FoxPaul.Fox 

How to create a custom button to a Visualforce Email Template that has an Attachment

I've created a visualforce email template that has an attachment on it. It works really well when I click Send an Email, choose the contact, then choose the Template. However, I've created a custom link on the object that says Email. I want it to open up the email and automatically fill in the contact and the template. That way the user can change the body before sending it. When I click on the button it fills in the body from the template but there's no attachment! If I then select the template again, the attachment shows up.

 

There are merge fields from the RelatedTo and the Recipient in the body of the template which are working, so I don't know what is wrong.

 

Here's the link which passes the Contact, Quote ID, and Template ID to the Send Email page:

 

/_ui/core/email/author/EmailAuthor?p3_lkid={!Quote__c.Id}&retURL=%2F{!Quote__c.Id}&p2_lkid={!Quote__c.ContactId__c}&template_id=00XA0000000QX8G

 And here's the template that it's using:

 

<messaging:emailTemplate subject="{!relatedTo.Type__c} {!relatedTo.Name} for {!recipient.Account.Name}" recipientType="Contact" relatedToType="Quote__c"> <messaging:plainTextEmailBody > Dear {!recipient.FirstName} {!recipient.LastName}, I have attached the {!relatedTo.Type__c}, as we discussed. Please call me if you have any questions. Sincerely, {!$User.FirstName} {!$User.LastName} {!$User.Phone} </messaging:plainTextEmailBody> <messaging:attachment renderAs="PDF" filename="{!relatedTo.Type__c} {!relatedTo.Name} for {!recipient.Account.Name}"> <c:quote quoteId="{!relatedTo.Id}"/> </messaging:attachment> </messaging:emailTemplate>

 

 

 

 

 

BshardiBshardi

Paul,

 

Did you ever find a solution for creating a link to a visualforce email template and have it attach the attachment as well? If so, could you share what you did? I'm running into the same problem.

 

Thanks,

 

Brandon

Paul.FoxPaul.Fox

Yes, just add &new_template=1 to the link, and it works. Here's the link that I used in the end:

 

/_ui/core/email/author/EmailAuthor?p3_lkid={!Quote__c.Id}&retURL=%2F{!Quote__c.Id}&p2_lkid={!Quote__c.ContactId__c}&new_template=1&template_id=00X300000018TZt

BshardiBshardi
Thanks Paul, that worked perfectly!