• ksareen
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

I am trying to write a batch apex job that will cycle through a list of records..

 

For each record, I need to get the VF Document related to it as a PDF and email it as an attachment.

 

The PDF always comes across as blank. I know I must bemissing something small because the exact same code works in a static apex class......

 

Can someone please help me resolve this?

 

Note: the code attached just attaches the file to the object for testing purposes...

 

this is the execute method. Everything else works except the actual PDF is empty

 

 

Map<ID,MYOBJECT__c> mFSA = New Map<ID,MYOBJECT__c>((MYOBJECT__c[])(database.query(query)));
    
    
    PageReference pr;
    blob pdf;
    
    For(FSA__c f : mFSA.values()){
    
        pr = New PageReference('/apex/ReportPDF?id=' + f.id ); 

        pdf = pr.getContentAsPDF();
        
        Attachment a = New Attachment();
        a.body = pdf;
        a.parentID = f.id;
        a.Name = 'FSA.pdf';
        insert a;
        
    
    }