+ Start a Discussion
sushant sussushant sus 

Schedule a report to send as email from workflow

I have to send a report attached as csv in email. i am using work flow with visual force email template 
Visual forceTemplate code 

<messaging:emailTemplate subject="SFDC AUTO EMAIL : CAP SUMMARY" recipientType="User" >
<messaging:plainTextEmailBody >
Hi,
</messaging:plainTextEmailBody>

<messaging:attachment filename="CapSummary.csv" >

<c:ReportExportController xstrRptname="00O0k000000SNDn"/>  // hard coded value in class for testing please refer below 
</messaging:attachment>
</messaging:emailTemplate>

Vf Component :
<apex:component controller="CSVStream" access="global">
     <apex:attribute name="xstrRptname" description="report ID" type="String" assignTo="{!strRptname}"/>
     
      <apex:outputText value="{!CSVStreamvalue}" escape="false"/>
</apex:component>

Apex class:
public without sharing class CSVStream {

    public static Boolean isTest;
    public static String strEmailAddr;
    public static String strOut{get;set;}
    public static Boolean restRequested;
    public String strEmail{get;set;}
    public String strRptname{get;set;}

    void CSVStream () {

            strOut = '';
            
                   
     }

    public String getCSVStreamvalue() {

        restRequested = System.isFuture() || System.isScheduled();
        executeRpt();
        return strOut;
    }

    public void executeRpt() {

        String requestURL;
       // requestURL = '/00O0k000000SNDn' + strRptname + '?csv=1&exp=1';
        requestURL = '/00O0k000000SNDn'+'?export=1&enc=UTF-8&xf=csv'; // hard coded report id 
        strOut = new PageReference(requestURL).getContent().toString();
        System.debug('CALLING executeRpt:  output= ' + strOut );
    }

}

I fire workflow base on condition which call this email alert with vf email template ...

Thing that figure out 
in vf component if i comment this line 
<apex:outputText value="{!CSVStreamvalue}" escape="false"/>
i am getting blank csv . other wise i am not receving any mail .

Other thing i debug apex code in console and it return data. i was able to get debug log of "CALLING executeRpt:  output"

I request developer community to help me on this ..Thanks 

 
sushant sussushant sus
IS this issue is because of getcontent() in apex class ....Any idea.....