0

I have a VisualForce template for an email, and this also has a PDF attachment similar to the email itself. When I run the Send Test and Verify Merge Fields it creates it fine, populates the fields and creates the attachment.

I've created a URL hack button to pass the Order, email address and other related info, and when I click this button on the Order it generates the email no problem, but not the attachment.

If I then select the same template from the Select Template option, it regenerates the email and then does create the attachment.

Why doesn't it create it from the button?? Help! It used to work before I defaulted the recipient email address, but now even if I remove that from the button hack it still doesn't work.

/_ui/core/email/author/EmailAuthor?rtype=003
&p3_lkid={!Order.Id}
&retURL=%2F{!Order.Id}
&p5={!$User.Email}
&p2_lkid={!Order.CustomerAuthorizedById}
&template_id=00XO0000000Ek5M

And my VF template:

<messaging:emailTemplate subject="Return Authorisation #: 
{!relatedTo.OrderNumber}" recipientType="Contact" 
replyTo="[email protected]" relatedToType="Order">
<messaging:htmlEmailBody >
<html>
    <style>
        body { 
        font-family: Verdana, Tahoma, sans-serif}

        table, th, td {
        border-collapse: collapse;
        }
    </style>        
    <body>          
        <table border="0" cellspacing="0" cellpadding="0" width="100%" id="table1" style="font-size:10px; text-align:right">
            <tr>
                <td>
                    <center><img src='https://c.cs5.content.force.com/servlet/servlet.ImageServer?id=015O0000000n8WP&oid=00DO0000000VuvS&lastMod=1465879820000' title="logo" /></center>
                    <br/><br/>
                    <apex:outputText value="Date: {0,date,dd' 'MMMM', 'yyyy}" styleClass="tright">
                        <apex:param value="{!TODAY()}" />
                    </apex:outputText><br/>
                </td>
            </tr>
        </table>
        <table border="0" cellspacing="0" cellpadding="0" width="100%" id="table2">
            <tr>
                <td>
                    {!relatedTo.Email_Notes__c}<br/><br/>
                </td>
            </tr>
            <tr>
                <td>
                    <b>Return Authorisation #: {!relatedTo.OrderNumber}</b>
                    <br/><br/>
                    Attached is your RMA (Return Maintenance Authority) return form as requested. Please print it and attach it to the parcel.
                    <br/><br/>
                    <strong>THE RMA NUMBER ABOVE MUST BE CLEARLY MARKED ON THE OUTSIDE OF THE PARCEL BEING RETURNED</strong>
                    <br/><br/>
                    Please ensure that the goods are sufficiently packaged to ensure that no damage occurs during transit.<br/><br/>
                    If you have any queries or, want to follow up on the collection relating to this return, please contact
                    xxx on <strong>0800 999999</strong> or email <strong><a href="mailto:[email protected]">[email protected]</a></strong>.
                </td>
            </tr>
            <hr/>
        </table>
        <!--Addresses -->
        <hr/>
        <table border="0" cellspacing="0" cellpadding="0" width="100%" id="table3">
            <tr>    
                <td width="48%">
                    <b>Customer Details:</b><br/>
                    <b>{!relatedTo.Account.Name}</b><br/>
                    {!relatedTo.BillingStreet}<br/>
                    {!relatedTo.BillingPostalCode} {!relatedTo.BillingCity}
                    <br/><br/>
                    <b>Account Number: </b>{!relatedTo.Account.AccountNumber}<br/>
                </td>
                <td width="2%">&nbsp;</td>
                <td valign="top">
                    <b>Delivery Address for Return:</b><br/>
                    {!$Organization.Name}<br/>
                    {!relatedTo.ShippingStreet}<br/>
                    {!relatedTo.ShippingPostalCode} {!relatedTo.ShippingCity}
                </td> 
            </tr>
        </table>
        <br/>
        <hr/>


        <table border="0" width="100%" id="table4" style="font-size:10px">
            <tr>
                <td>
                    <b>Customer Contact name:</b> {!relatedTo.CustomerAuthorizedBy.Name}<br/>
                    <b>Contact email:</b> {!relatedTo.CustomerAuthorizedBy.Email}<br/>
                    <b>Contact phone:</b> {!relatedTo.CustomerAuthorizedBy.Phone}<br/><br/>
                </td>
            </tr>    
            <tr>
                <td valign="top">
                    <b>Created by:</b> {!relatedTo.CreatedBy.Name}<br/>
                    <b>Source Order :</b> {!relatedTo.RMA_Source_Order__r.OrderNumber}<br/>
                    <b>Source Invoice:</b> {!relatedTo.RMA_Source_Invoice__r.Name}<br/>
                    <b>Case:</b> {!relatedTo.RMA_Source_Document__c}
                </td>
            </tr>    
        </table>
        <br/>
        <hr/>
        <table border="0" width="100%" id="table5" style="font-size:10px">
            <tr>
                <td bgcolor="#C0C0C0"><h4>Product</h4></td>
                <td bgcolor="#C0C0C0"><h4>Description</h4></td>
    <!--            <td bgcolor="#C0C0C0"><h4>Image</h4></td>-->
                <td bgcolor="#C0C0C0"><h4>Quantity</h4></td>
                <td bgcolor="#C0C0C0"><h4>Unit</h4></td>
            </tr>
            <tr>
                <apex:repeat value="{!relatedTo.OrderItems}" var="line">
                    <tr>
                        <td>{!line.PricebookEntry.ProductCode}</td>
                        <td>{!line.Description}</td>
    <!--                    <td ALIGN="center"><img src='{!line.PricebookEntry.Product2.URL_Picture__c}'/></td>             -->
                        <td>{!line.Quantity}</td>
                        <td>{!line.Unit__c}</td>
                    </tr>
                </apex:repeat>  
            </tr>
        </table>
        <br/>
    </body>
</html>
</messaging:htmlEmailBody>

<!-- ----------------------------------------------------------------------------------------------------------------------- -->        
<messaging:attachment renderAs="pdf" filename="{!relatedTo.name}">               
<html>
    <style>
        body { 
        font-size:10px;
        font-family: Verdana, Tahoma, sans-serif}

        h2 {
        font-size:14px; 
        font-weight: bold; 
        line-height: 16px}

        h3 {
        font-size:12px; 
        font-weight: bold; 
        line-height: 14px }

        h4 {
        font-size:11px; 
        font-weight: bold; 
        line-height:13px}

        table, th, td {
        border-collapse: collapse;
        }

        th { font-weight: bold; }

        @page {
            counter-increment: pages;
            @top-center {content: counter(page) " of " counter(pages);}
            @bottom-center {content: element(footer);}
        }
        div.footer {position: running(footer)}
        #pageNum: before {content: counter(pages);}
    </style>        
    <body>
        <div class="footer" style="font-size:8pt;text-align:center">
            <p align="center"><i>Copyright {!$Organization.Name}</i></p>

            <apex:outputText value="Printed: {! NOW() }"/>     
        </div>
        <!--Logo and RMA number -->
        <table border="0" cellspacing="0" cellpadding="0" width="100%" id="table1">
            <tr>
                <td>
                    <img src='{!URLFOR($Resource.xxx)}' title="logo" />
                </td>
            </tr>
            <hr/>
        </table>
        <table border="0" cellspacing="0" cellpadding="0" width="100%" id="table1">
            <tr>
                <td>
                    This number must be attached to all items being returned<br/>
                </td>
                <td align="right">
                    <h2>Return Authorisation #: {!relatedTo.OrderNumber}</h2>
                </td>
            </tr>
            <hr/>
        </table>

        <!--Addresses -->
        <table border="0" cellspacing="0" cellpadding="0" width="100%" id="table1">
            <tr>    
                <td width="48%">
                    <h4>Customer Details</h4>
                    <h3>{!relatedTo.Account.Name}</h3>
                    {!relatedTo.BillingStreet}<br/>
                    {!relatedTo.BillingPostalCode} {!relatedTo.BillingCity}
                    <br/><br/>
                    <b>Account Number: </b>{!relatedTo.Account.AccountNumber}<br/>
                </td>
                <td width="4%">&nbsp;</td>
                <td valign="top">
                    <apex:outputText value="Date: {0,date,dd' 'MMMM', 'yyyy}">
                        <apex:param value="{!TODAY()}" />
                    </apex:outputText><br/>
                    <h4>Delivery Address for Return</h4>
                    {!$Organization.Name}<br/>
                    {!relatedTo.ShippingStreet}<br/>
                    {!relatedTo.ShippingPostalCode} {!relatedTo.ShippingCity}
                </td> 
            </tr>
        </table>
        <br/>
        <hr/>

        <table border="0" width="100%" id="table2">
            <tr>
                <td>
                    <b>Contact name:</b> {!relatedTo.CustomerAuthorizedBy.Name}<br/>
                    <b>Contact email:</b> {!relatedTo.CustomerAuthorizedBy.Email}<br/>
                    <b>Contact phone:</b> {!relatedTo.CustomerAuthorizedBy.Phone}
                </td>
                <td>
                    <b>Created by:</b> {!relatedTo.CreatedBy.Name}<br/>
                    <b>Source Order :</b> {!relatedTo.RMA_Source_Order__r.OrderNumber}<br/>
                    <b>Source Invoice:</b> {!relatedTo.RMA_Source_Invoice__r.Name}<br/>
                    <b>Case:</b> {!relatedTo.RMA_Source_Document__c}
                </td>
            </tr>    
        </table>
        <br/>
        <hr/>
        <table border="0" width="100%" id="table3">
            <tr>
                <td bgcolor="#C0C0C0"><h4>Product</h4></td>
                <td bgcolor="#C0C0C0"><h4>Description</h4></td>
    <!--            <td bgcolor="#C0C0C0"><h4>Image</h4></td>-->
                <td bgcolor="#C0C0C0"><h4>Quantity</h4></td>
                <td bgcolor="#C0C0C0"><h4>Unit</h4></td>
            </tr>
            <apex:repeat value="{!relatedTo.OrderItems}" var="line">
                <tr>
                    <td>{!line.PricebookEntry.ProductCode}</td>
                    <td>{!line.Description}</td>
    <!--                    <td ALIGN="center"><img src='{!line.PricebookEntry.Product2.URL_Picture__c}'/></td>             -->
                    <td>{!line.Quantity}</td>
                    <td>{!line.Unit__c}</td>
                </tr>
            </apex:repeat>  

        </table>
        <br/>
        <hr/>
        <table width="100%" id="table5">
            <tr>
                <td><b>This is your RMA (Return Maintenance Authority) return form as requested.<br/>
                    THE RMA NUMBER ABOVE MUST BE CLEARLY MARKED ON THE OUTSIDE OF THE PARCEL BEING RETURNED</b>
                    <br/>
                    Please ensure that the goods are sufficiently packaged to ensure that no damage occurs during transit.<br/>
                    If you have any queries or, want to follow up on the collection relating to this return, please contact
                    xxx on <b>0800 999999</b> or <b>email [email protected]</b>
                </td>
            </tr>
            <tr>
                <td alight="center">
                    <h3>Return Reason - please complete</h3>
                    <table border="1" width="95%" height="100px">
                        <tr><td height="100px"></td></tr>
                    </table>
                </td>
            </tr>
        </table>
    </body>
</html>

</messaging:attachment>      

</messaging:emailTemplate>

1 Answer 1

0

After looking further I found an answer here https://success.salesforce.com/answers?id=90630000000gotsAAA in the comments further down (it is not the marked answer!). All that is required to make it work is adding '&new_template=true' to the url hack, so it looks like this now:

/_ui/core/email/author/EmailAuthor?
rtype=003
&p3_lkid={!Order.Id}
&retURL=%2F{!Order.Id}
&template_id=00XO0000000RQ4J
&p5={!$User.Email}
&p2_lkid={!Order.CustomerAuthorizedById}
&new_template=true

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .