You need to sign in to do that
Don't have an account?
Nisha Vishwasrao
getContentAsPDF() returning blank PDF
I am facing the issue where PDF getting generated from VF page are blank.
I do not have the corresponding critical update activated to treat getContentAsPDF() Methods as Callouts.
The method getContentAsPDF() is invoked from a method SendPDF on custom controller class. And this SendPDF method is getting called as an action from a VF page.
Below is the code of this method. After upsert Survey, trigger class gets invoked on Survey object.
public static void SendPDF()
{
String AccountId = ApexPages.currentPage().getParameters().get('id');
String SurveyId = ApexPages.currentPage().getParameters().get('survey');
Survey__c[] Survey = [ SELECT Id, Name, Status__c, Send_PDF__c
FROM Survey__c
WHERE Id = :SurveyId LIMIT 1 ];
if (Survey[0].Status__c.equals('Complete') &&
(Survey[0].Send_PDF__c == null || ! Survey[0].Send_PDF__c.equals('Sent')))
{
PageReference pdfReport = Page.SurveyPg;
pdfReport.getParameters().put('id', AccountId);
pdfReport.getParameters().put('survey', SurveyId );
//System.debug(pdfReport);
Blob PDFBlob = pdfReport.getcontentAsPdf();
String PDFName = 'Survey' + Survey[0].Name + '.pdf';
Attachment attachment = new Attachment();
attachment.Body = PDFBlob;
attachment.Name = PDFName;
attachment.ParentId = SurveyId;
insert attachment;
Survey[0].Send_PDF__c = 'Sent';
upsert Survey;
}
}
We are not sending the PDF as email but instead attaching it to the survey record.
I am not directly calling the method from trigger and also do not have the critical update activated but still facing the issue.
Is there something else I need to do to make sure that getContentAsPDF() works correctly?
I do not have the corresponding critical update activated to treat getContentAsPDF() Methods as Callouts.
The method getContentAsPDF() is invoked from a method SendPDF on custom controller class. And this SendPDF method is getting called as an action from a VF page.
Below is the code of this method. After upsert Survey, trigger class gets invoked on Survey object.
public static void SendPDF()
{
String AccountId = ApexPages.currentPage().getParameters().get('id');
String SurveyId = ApexPages.currentPage().getParameters().get('survey');
Survey__c[] Survey = [ SELECT Id, Name, Status__c, Send_PDF__c
FROM Survey__c
WHERE Id = :SurveyId LIMIT 1 ];
if (Survey[0].Status__c.equals('Complete') &&
(Survey[0].Send_PDF__c == null || ! Survey[0].Send_PDF__c.equals('Sent')))
{
PageReference pdfReport = Page.SurveyPg;
pdfReport.getParameters().put('id', AccountId);
pdfReport.getParameters().put('survey', SurveyId );
//System.debug(pdfReport);
Blob PDFBlob = pdfReport.getcontentAsPdf();
String PDFName = 'Survey' + Survey[0].Name + '.pdf';
Attachment attachment = new Attachment();
attachment.Body = PDFBlob;
attachment.Name = PDFName;
attachment.ParentId = SurveyId;
insert attachment;
Survey[0].Send_PDF__c = 'Sent';
upsert Survey;
}
}
We are not sending the PDF as email but instead attaching it to the survey record.
I am not directly calling the method from trigger and also do not have the critical update activated but still facing the issue.
Is there something else I need to do to make sure that getContentAsPDF() works correctly?
can you check pgf page in brouser and debug . Add Bellow code if pdf page working proper with passing account & suryid .
Regards ,
Harish.R.