You need to sign in to do that
Don't have an account?

PDF file Creation from a scheduled class
Hi,
I need to create a pdf file and insert it to the attachment object as record. This would fire as a scheduled class and not on a button click in a Visualforce page.
The code is as below:
global class OrderDispatchToTopcall implements Schedulable{
global void execute(SchedulableContext SC) {
PageReference pdf = Page.MerchantDeliveryChecklist;
pdf.getParameters().put('id', 'a1CR000000044H8');
pdf.getParameters().put('pageType', 'NCHODC');
pdf.setRedirect(true);
Blob b=pdf.getContentAsPDF();
Attachment attachment=new Attachment(ParentId='a1CR000000044H8',body=b,ContentType='application/pdf',Name='test.pdf');
insert attachment;
}
}
When this class runs it creates an attachment record but it is in a invalid format.
But when I call the same PDF creation code from button on a visualforce page, the attachment is created and it is a valid file.
Can somebody help me why I am not able to create a valid pdf file when the code runs from a schedular
there are issues with getContent() when it is called from a testMethod, maybe the same bug applies to scheduled classes and getContentAsPDF as well?
See my post here:
http://community.salesforce.com/t5/Visualforce-Development/getContent-fails-when-called-from-testMethod/m-p/182645
I cannot see any obvious mistake in your code. One thing you can try is to change the pdf VF page to renderAs="pdf" and then use getContent instead of getContentAsPDF.
Did you log a case?
u cant use getcontent and getContentAsPDF methods in a class which is scheduled..