function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
EvannnEvannn 

Too many nested getContent calls when trying to attach a Visualforce page as a PDF

Hi all,
 
I am new to Apex programming and am getting weird little error when i try to attach a PDF to Notes and Attachments.  I'm rendering a Visualforce page as a PDF, with an extension to an "EstimateProposal" Apex class.  The project compiles fine, but when I run it in the UI, I get an error "EXCEPTION_THROWN|[70,24]|System.VisualforceException: Too many nested getContent calls."  Funny thing is, the code block works when I execute it anonymously, just not it's part of my VF controller execution flow.  Anyone seen this before or could point me to a resource to fix it?  Any help would be greatly appreciated!
 
****APEX CLASS**** 
    public PageReference attachQuote() {
        PageReference pdfPage = Page.GenerateProposal;
        pdfPage.getParameters().put('id',this.opp.Id);
        Blob pdfBlob = pdfPage.getContent(); 
        Attachment proposalPDF = new Attachment (parentId = this.opp.Id, name=this.opp.name + '.pdf', body = pdfBlob);
        insert proposalPDF;
        return null;  
    } 
}
 

 
****VISUAL FORCE PAGE****
<apex:page standardController="Opportunity" extensions="EstimateProposal" renderAs="pdf" showHeader="false" sidebar="false" >
nellymnjnellymnj

Hi Evann, have you resolved the issue? I have the same problem , tried several things modifying the code - nothing works. Any thougths would be greatly appreciated.

OnkiOnki

no one is availabe to solve this issue Also no one from salesforce guy know why this error is coming...........

magandrezmagandrez

Hi,

 

I would like to open this and see if there is any possible solution, because I have the same issue when saving a PDF that has been created. The VF page to create the PDF is in place (it was before me) and this is the controller that creates the PDF:

 

public class invoicePDFController {

    public invoicePDFController(ApexPages.StandardController controller) {
     }
String InvoiceId = ApexPages.currentPage().getParameters().get('id');
   
    
    public ApexPages.StandardSetController setCon {
    	
    	
        get {
            if(setCon == null) {
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
                      [select Code__c, Discount__c, Invoice__c, Label__c, Total_EUR_excl_VAT__c, Total_EUR_incl_VAT__c, 
                      Total_Taxes__c, Unit_Price_EUR_excl_VAT__c, Unit_Price_EUR_incl_VAT__c, 
                      VAT__c, Quantity__c from Invoice_Line__c where Invoice__c = :InvoiceId]));
            }
            return setCon;
        }
        set;
    }

    // Initialize setCon and return a list of records  
    
    public List<Invoice_Line__c> getInvoicelines() {
         return (List<Invoice_Line__c>) setCon.getRecords();
    }    
    
}

 I'm trying to save a PDF when its created (an invoice), in order to that I placed this code in the controller constructor:

 

String Nam= ApexPages.currentPage().getParameters().get('Name'); 
Document d = new Document();
    
    d.Body = ApexPages.currentPage().getContent();
    d.ContentType = 'pdf';
    d.Description = 'Invoice: '+ Nam;
    d.FolderId = '00lU0000000N5Y5';
    d.Name =  nam;
    
insert d;

 

But I get the error "Too many nested getContent " when the new window that should show the PDF opens.

 

Has anyone faced this problem before?

 

Any help is very welcome.

 

Thanks,

 

MGA

Pankaj Kumar 36Pankaj Kumar 36
Hey did u get solution for this problem..