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
nasir jawednasir jawed 

SetInline is not working when an email is send

Hi All,

 

I have written a Email controller,which is attached to a vf page.There is an ORDER object which has contact__c field as a lookup.An another object called Job__c,which is a related list to the Order__c object and has a field called job_Flag__c ,When ever the job_Flag__c field is true ,an email is send to the contact email field which is in the Order object.

What i want is ,when i send an email and the user opens the email he should see the entire VF page in the body of the email.

 

I am using setInline(true) in the attachment method.But i cannot find any changed in the email.It is still coming as an attachment.

 

The code i had attached below and the VF page also.

<apex:page standardController="Order__c"  showHeader="false" extensions="PopulateOrderValues" renderAs="pdf" >
<html>
    <head>
        <title>Order Received</title>
    </head>
    <body>
    <table width="600" border="0" cellpadding="0" cellspacing="0">
        <tr>
            <td><img src="https://c.cs5.content.force.com/servlet/servlet.ImageServer?id=015O00000008wm7&oid=00DO0000000CqOz&lastMod=1320735422000"/></td>
        </tr>
        <tr>        
            <td height="70" align="center" valign="top"><font color="#646464" size="5" face="Helvetica, Arial, sans-serif"><Center>THANK YOU FOR YOUR ORDER!</center></font><font face="Helvetica, Arial, sans-serif" color="#646464" size="2" style="font-size:12px">We will send you a notification once your order is ready for shipment.</font></td>
        </tr>
        <tr>
            <td height="30" align="center" valign="top"><img src="" width="600" height="1"/></td>
        </tr>
        <tr>
            <td>
            <table width="600" border="0" cellpadding="0" cellspacing="0">
                <tr>                
                    <td width="25">&nbsp;</td>
                    <td width="550" height="30" valign="top"><font face="Helvetica, Arial, sans-serif" color="#646464" size="3" style="font-size:19px">ORDER INFORMATION</font></td>
                    <td width="25">&nbsp;</td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                <td>
                    <table width="550" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                        
                            <td width="95"><strong><font face="Helvetica, Arial, sans-serif" color="#646464" size="2" style="font-size:12px">Order number</font></strong></td>
                            <td width="180"><font face="Helvetica, Arial, sans-serif" color="#646464" size="2" style="font-size:12px">{!Order__c.Order_ID__c}</font></td>
                            <td width="95" rowspan="5" valign="top"><strong><font face="Helvetica, Arial, sans-serif" color="#646464" size="2" style="font-size:12px">Deliver to</font></strong></td>
                            <td width="180" rowspan="5" valign="top"><font face="Helvetica, Arial, sans-serif" color="#646464" size="2" style="font-size:12px">{!currentOrder.Account__r.PersonMailingStreet}, {!currentOrder.Account__r.PersonMailingCity},
                            {!currentOrder.Account__r.PersonMailingState},{!currentOrder.Account__r.PersonMailingPostalCode},{!currentOrder.Account__r.PersonMailingCountry}, </font></td>
                        </tr>
                        <tr>
                            <td><strong><font face="Helvetica, Arial, sans-serif" color="#646464" size="2" style="font-size:12px">Cost centre</font></strong></td>
                            <td><font face="Helvetica, Arial, sans-serif" color="#646464" size="2" style="font-size:12px">{!Order__c.Cost_Center__c}</font></td>
                        </tr>
                        
                        <tr>        
                            <td><strong><font face="Helvetica, Arial, sans-serif" color="#646464" size="2" style="font-size:12px">Employee</font></strong></td>
                            <td><font face="Helvetica, Arial, sans-serif" color="#646464" size="2" style="font-size:12px">{!currentOrder.Contact__r.Name}</font></td>
                        </tr>
                        <tr>
                            <td><strong><font face="Helvetica, Arial, sans-serif" color="#646464" size="2" style="font-size:12px">Phone</font></strong></td>
                            <td><font face="Helvetica, Arial, sans-serif" color="#646464" size="2" style="font-size:12px">{!currentOrder.Account__r.Phone}</font></td>
                        </tr>
                        
                        <tr>
                            <td><strong><font face="Helvetica, Arial, sans-serif" color="#646464" size="2" style="font-size:12px">Email</font></strong></td>
                            <td><font face="Helvetica, Arial, sans-serif" color="#646464" size="2" style="font-size:12px">{!Order__c.Contact_Email__c}</font></td>
                        </tr>
                    </table>
                </td>
            <td>&nbsp;</td>
            </tr>     
            <tr>
                <td>&nbsp;</td>
                <td height="20">&nbsp;</td>
                <td>&nbsp;</td>
            </tr>
      
            <style type="text/css">        
                .odd {
                    background-color: #fae1c3;
                }
                .even {
                    background-color: #f2f2e8;
                }
                
                .Lastcolour{
                    background-color: #E3E3D9;
                }
                
                .h { width:1000px;
                   height:150px;
                }
                 
                .pr { width:900px;
                height:100px;}          
            </style>
           
            <apex:form > 
            <apex:pageBlock >
                <apex:dataTable value="{!job}" var="j" style="Helvetica, Arial, sans-serif;valign='right'" rowClasses="odd,even"  >
                           
                    <apex:column styleClass="h" >
                        <apex:facet name="header" ><td valign="top" width="10%"><b>Item#</b></td></apex:facet>
                        <td valign="top" width="10%"><apex:outputText value="{!j.Job_ID__c}" styleClass="mystyle" /></td>
                    </apex:column> 
                    
                    <apex:column styleClass="h"  >
                        <apex:facet name="header"><td valign="top" width="10%"><b>Date</b></td></apex:facet>
                        <td valign="top"><apex:outputField value="{!Order__c.Order_Date__c}"  styleClass="mystyle"/></td>
                    </apex:column>
                    
                    <apex:column styleClass="h">
                        <apex:facet name="header"><td valign="top" width="10%"><b>Quantity</b></td></apex:facet>
                        <td valign="top"><apex:outputText value="{!j.Quantity__c}"  styleClass="mystyle"/></td>
                    </apex:column>
                    
                    <apex:column styleClass="pr" >
                        <apex:facet name="header">Product</apex:facet> 
                        <table border="0" >
                            <tr>
                                <td valign="top" ><b><i>EMC Business Card Front</i></b> &nbsp; {!j.Front_Template_Name__c}</td>
                            </tr>
                            
                            <tr>
                                <td valign="top"><b>Delivery</b> &nbsp; {!j.Front_Template_Name__c}</td>
                            </tr>
                            
                            <tr>
                                <td valign="top"><b>Base</b> &nbsp; {!j.Material_Type__c}</td>
                            </tr>
                            
                            <tr>
                                <td valign="top"><b>Lamination</b> &nbsp; {!j.Lamination__c}</td>
                            </tr>
                            
                            <tr>
                                <td valign="top"><b>Printed Sides</b>&nbsp; {!j.Printing_Side__c}</td>
                            </tr>
                            
                            <tr>
                                <td valign="top"><b>Dimensions</b>&nbsp; {!j.Dimension__c}</td>
                            </tr>
                            
                            <tr>
                                <td valign="top" ><b>Delivery Zone</b> &nbsp;{!j.Delivery_State__c}</td>
                            </tr>
                            </table> 
                    
                    </apex:column> 
                                
                                                   
                    
                    <apex:column styleClass="h" >
                        <apex:facet name="header"><td valign="top" width="10%"><b>Cost</b></td></apex:facet>
                        <td valign="top" width="10%"><apex:outputText value="{!j.Item_Price__c}"  styleClass="mystyle"/></td>
                    </apex:column>
                            
                </apex:dataTable>
            </apex:pageBlock> 
            </apex:form> 
   
    
            <table  ALIGN="right" face="Helvetica, Arial, sans-serif" size="2" style="font-size:12px">
                <tr>
                    <td style="font-size:15px" width="45%" ALIGN="left"><Strong>Cost Of Items</Strong></td>
                    <td width="17%" style="font-size:15px"><apex:outputText value="{!Order__c.Cost_of_Items__c}"/></td>
                </tr> 
                <tr>  
                    <td style="font-size:15px"  width="45%" ALIGN="left"><Strong><apex:outputText value="Delivery"/></Strong></td>
                    <td width="17%" style="font-size:15px"> <apex:outputText value="{!Order__c.Freight_Cost__c}"/></td>
                </tr>    
                <tr>
                   <td style="font-size:15px" width="45%" ALIGN="left"> <Strong><apex:outputText value="Total"/></Strong></td>
                    <td width="17%" style="font-size:15px"> <Strong><apex:outputText value="{!Order__c.Total_Charges__c}"/></Strong></td>
                 </tr>
            </table>   
                      
               
        </table>
            </td>
            </tr> 
            
            
                  
                    
            <table width="47%">
                <tr>
                    <td Align="Center" style="background-color:#E3E3D9;font-size:26px;" ><p><br>Best regards,</br>The EfficientLive Team</p></td>
                </tr>
            </table>
                    
        </table>           
    </body>
</html>
            
</apex:page>

 

public  class OrderEmail {

    public OrderEmail() {

    }

    public String subject;
    public String body='Please click the link';  
    public string jobId;
    
    public OrderEmail(ApexPages.StandardController controller) {
        jobId=ApexPages.currentPage().getParameters().get('jobId');
    }
      
    public void sendEmail(){   
        jobId=ApexPages.currentPage().getParameters().get('jobId');      
           
        Job__c tempJob = [Select Order__r.Account__c, Order__r.Account__r.IsPersonAccount, 
            Order__c, Order__r.Contact__c, Order__r.Contact__r.Email, Job_Flag__c, 
            Order__r.Account__r.PersonEmail
            from Job__c 
            
            where id=:jobId
            ];
        
            
        If(tempJob.Job_Flag__c== true){  
                
            Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();  
                
            PageReference p = Page.edm_orderreceived;
            p.getParameters().put('id',tempJob.Order__c);
            p.setRedirect(true);                
            // Take the PDF content
            Blob b = p.getContent();
               
            // Create the email attachment
            Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
            efa.setFileName('Order.pdf');
            efa.setBody(b);
          
            efa.setInline(true);
            system.debug('Attachment:'+ efa);
            
            if(tempJob.Order__r.Account__r.IsPersonAccount){
                email.setToAddresses (new String[] {tempJob.Order__r.Account__r.PersonEmail});                  
            }else{
                email.setToAddresses (new String[] {tempJob.Order__r.Contact__r.Email});
            }
            
            email.setSubject( subject );
            email.setPlainTextBody(body );          
                
            email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});

            Messaging.sendEmail(new Messaging.Email[] {email});                
      
        }
    }
    

}