I'm trying to create a csv file attached to a visualforce email template. The csv file is based on a report that has a bunch of columns (fields) already, and all that I usually do is pass the Quote ID and the report fills in the line items.

I've tried the below and it generates the report in a CSV but with no data.

Visualforce Email Template Attachment

<messaging:attachment filename="{!relatedTo.Name}-{!relatedTo.EmailPDFName__c}.csv" > 
<c:QuoteCSV xtheQuoteID="{!relatedTo.Id}" />

Visualforce Component

<apex:attribute name="xtheQuoteID" description="quote ID" type="String" assignTo="{!theQuoteID}"/>

<apex:outputText value="{!CSVStream}" escape="false"/> 

Apex Controller NOTE: I tried to re-engineer from another process

public class QuoteLineEmailController {

  public static Boolean isTest;
  public static String strOut = '';
  public String theQuoteID{get;set;}

  public void CSVStream () {
   strOut = '';

  public String getCSVStream() {
    return strOut;

   public void executeRpt() {
    String requestURL;
    requestURL = '/00OF0000005ueLL?xf=localecvs&export=&pv0=' + theQuoteID + '?csv=1&exp=1';
    strOut = Test.isRunningTest() ? 'test' : new PageReference(requestURL).getContent().toString();
    System.debug('CALLING executeRpt:  output= ' + strOut );

1 Answer 1


Scrapped the component section and utilized a simple query in the component to grab the following fields.

Created a new format of VisualForce component:

<apex:component controller="QuoteLineEmailController" access="global">
<apex:attribute name="theQuoteID" type="Id" description="Id of the Quote" assignTo="{!QuoteID}"/>
    <apex:repeat var="CSVQLI" value="{!CSVQuoteLines}" >
            <apex:variable value="{!Quotee}" var="Q">

You must log in to answer this question.

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