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

System.VisualforceException: Too many nested getContent calls in page extension
I have a page which is extended by the "EmailPDFController" class as seen bleow.
The problem is that the getContent call cuases an error and I have no idea why.
What I am trying to do is create a pdf and mail it to myself. Creating the pdf works fine but sending it to myself is not working.
See code below. Try and catch blocks are deliberatly commented out.
public with sharing class EmailPDFController {
public EmailPDFController (ApexPages.StandardController controller){
// try {
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[]{'firstname.lastname@company.domain'};
String[] CopyToAddresses = new String[]{'tname@company.domain','firstname.lastname@company.domain'};
mail.setToAddresses(toAddresses);
// mail.setCcAddresses(CopyToAddresses);
mail.setBccAddresses(CopyToAddresses);
mail.setReplyTo('x@y.com');
mail.setSenderDisplayName('x y');
mail.setSubject('PDF Invoise ');
// mail.setBccSender(false);
mail.setUseSignature(false);
String msg = '<p><b>Hellow</b></p>';
PageReference congratsPage = ApexPages.currentPage();
Blob b = congratsPage.getContent();
Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
efa.setFileName('MyPDF.pdf'); // neat - set name of PDF
efa.setBody(b); //attach the PDF
mail.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});
mail.setHtmlBody(msg);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail});
// } catch (Exception e){}
}
@IsTest(SeeAllData=true) public static void testEmailPDFController() {
ApexPages.StandardController c;
EmailPDFController EPDFC = new EmailPDFController(c);
try {
// System.assertEquals(EPDFC.EmailPDFController(),null);
}
catch (Exception e){}
}
}
The solution to this is to create two pages
Page1 is the page that contains the extension, page2 is the pdf page.
Then use the getparameters to get the ID from page1 and pass it to page2.
The get the content of page2.
This fixes the immedout problem but it appears that extensions can't send e-mails see my post
http://boards.developerforce.com/t5/Apex-Code-Development/Can-extensions-to-standard-controllers-send-E-Mails/m-p/498383
So it looks like custom controller time.
All Answers
Hi
see this
http://boards.developerforce.com/t5/Visualforce-Development/Too-many-nested-getContent-calls/m-p/311227#M38577
http://boardreader.com/thread/Community_Too_many_nested_getContent_cal_9nxjX6nyf.html
if your question is resolve please mark it as accept as a solution if not please let me know.
The solution to this is to create two pages
Page1 is the page that contains the extension, page2 is the pdf page.
Then use the getparameters to get the ID from page1 and pass it to page2.
The get the content of page2.
This fixes the immedout problem but it appears that extensions can't send e-mails see my post
http://boards.developerforce.com/t5/Apex-Code-Development/Can-extensions-to-standard-controllers-send-E-Mails/m-p/498383
So it looks like custom controller time.