You need to sign in to do that
Don't have an account?
Alexander Atkinson
Too many nested getContent calls error
Hello, I'm trying to implement a save to pdf functionality to my visual force page, but have ran into a problem of "Too many nested getContent calls".
Visual Force Page
Apex code for the savePDF
Visual Force Page
<apex:page showHeader="false" standardStylesheets="false" standardController="Event__c" extensions="SaveAsPdfExtension" action="{!savePdf}"> <header> <h1 align="center">VIPs for {!Event__c.Name}</h1> </header> <apex:repeat value="{! VIPs }" var="Guest"> <section class="container"> <div> <article> <h2>Name: {!Guest.Guest_Name__c }</h2> <h3>Description:</h3> <p>{!Guest.Guest__r.Description }</p> </article> </div> </section> </apex:repeat> </apex:page>
Apex code for the savePDF
public PageReference savePdf() { PageReference pdf = Page.Event_Crib_Sheet; pdf.getParameters().put('id',Event.Id); Attachment attach = new Attachment(); Blob body; try { body = pdf.getContentasPDF(); } catch (VisualforceException e) { body = Blob.valueOf(e.getMessage()); } attach.Body = body; attach.Name = pdfName; attach.IsPrivate = false; attach.ParentId = Event.Id; attach.Description = 'Created by ' + UserInfo.getName(); insert attach; return new PageReference('/'+ Event.Id); }
Greetings to you.
When you hit your page, after load it calls the method where you are doing document insertion task which again calls the same visual force page (PageReference pdf = Page.Event_Crib_Sheet;). So it will apparently create an infinite loop. To avoid this you have to create another visualforce page which is renderAs PDF and that page is assigned in the code.
Please refer to the below links with a similar discussion which might help you further with the above issue.
https://developer.salesforce.com/forums/?id=906F000000097DbIAI
https://developer.salesforce.com/forums/?id=906F0000000BPl1IAG
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks and Regards,
Khan Anas