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
nagasnagas 

email attachment

hi ,

 

I am working in a solution where i run a batch class which gives me the all the ids of an object based on some criteria. In this i need to collect all these ids and put it into a csv file and send an email with the csv file attached to the email.

 

Can anybody suggest me the code to accomplish this.

Rasmus MenckeRasmus Mencke

Use visualforce email templates to do that.

 

Take a look at this package as an example:

http://sites.force.com/appexchange/listingDetail?listingId=a0N300000016cYlEAI

 

Here is another example:

http://wiki.developerforce.com/index.php/VisualForceEmailTemplates_sample

nagasnagas

hi rasmus thanks for the reply but in my case i want it the file to be a CSV file and send as an attahcment with the email.

Rasmus MenckeRasmus Mencke

You can do that with Visualforce email templates.

 

Add a component like this into the template, this example is a PDF, but easy to change into a csv

 

 

<messaging:attachment renderas="pdf" filename="Opportunity_Products.pdf">

<img src="http://www.salesforce.com/common/assets/css/images/hdr_apexdn.gif" border="0"></img>

        <p>Dear {!recipient.name},</p>
        <p>Below is a list of products related to the Opportunity:<b> {!relatedTo.name}</b>.</p>
        <br/>Account: <i> {!relatedTo.Account.name}  </i>  
        <br/>Opportunity Owner: {!relatedTo.owner.name}
        <br/>Opportunity Amount: {!ROUND(relatedTo.Amount,0)} 
        <br/>Opportunity Close Date: {!relatedTo.CloseDate}  
   
        <p/>   
        


    <apex:datatable border="2" cellspacing="5" var="opp2" value="{!relatedTo.OpportunityLineItems}">
        <apex:facet name="header">Products associated with Opportunity {!relatedTo.name}</apex:facet>
        
          <apex:column value="{!opp2.PriceBookEntry.name}" headerValue="Product Name"/>
  
        <apex:column value="{!opp2.Quantity}" headerValue="Quantity" />
        <apex:column value="{!opp2.UnitPrice}" headerValue="Units" />
        <apex:column value="{!opp2.TotalPrice}" headerValue="Total Price" />
  
        
      </apex:datatable>


</messaging:attachment>   

 

 

 

 

jaya sai prasadjaya sai prasad
Hi,

If you want to send an Email with Attachment a native salesforce app MassMailer DOCS is perfect for you.

MassMailer DOCS let’s you send mass email attachments to your leads or contacts while securely storing your files with Rackspace Cloud Files.

You can try this app by installing from appexchange  -Massmailer Docs

You can learn more details about the product on this website - docs.massmailer.io