You need to sign in to do that
Don't have an account?
Itayb34
Pass Record id on Iframe Visualforce - Urgent
Hello
I have a Visualforce page embedded in an iframe into another visualforce page (see below), the iframed page is a PDF.
When I click the custom button, the fields in the PDF are empty, but when I save the PDF into "Notes & Attachments", the PDF is populated with the information from the record...
I know that I need to pass variable from the parent, but what needs to be done?
Custom Button: /apex/PdfGeneratorTemplate?id={!Monthly_Cloud_Bill__c.Id}
Class:
public with sharing class PdfGeneratorController { String parentId = ApexPages.currentPage().getParameters().get('id'); Monthly_Cloud_Bill__c MCB = [SELECT Account__r.Id, Account__r.Name from Monthly_Cloud_Bill__c WHERE Id = :parentId]; Account acc = MCB.Account__r; String AccountName = acc.Name; String AccountId = acc.Id; public PageReference savePdf() { //PageReference pdf = Page.PdfGeneratorTemplate; PageReference pdf = Page.InvoicePDF2; // add parent id to the parameters for standardcontroller pdf.getParameters().put('id',parentId); // create the new attachment Attachment attach = new Attachment(); // the contents of the attachment from the pdf Blob body; try { // returns the output of the page as a PDF body = pdf.getContent(); // need to pass unit test -- current bug } catch (VisualforceException e) { body = Blob.valueOf('Some Text'); } attach.Body = body; // add the user entered name attach.Name = AccountName + '.pdf'; attach.IsPrivate = false; // attach the pdf to the account attach.ParentId = parentId; insert attach; // send the user to the account to view results //return new PageReference('/'+parentId); return new PageReference('/'+'flow/Email_Cloud_Invoice?MBCID='+parentId + '&AccountID='+AccountId + '&AttachmentID='+doc.id+ '&retURL='+parentId); } }
Iframe PDF:
<apex:page standardController="Monthly_Cloud_Bill__c" showHeader="false" renderas="pdf"> <table border="0" cellspacing="0" cellpadding="0" width="100%" id="table1"> <tr> <td align="right"> <img src='{!URLFOR($Resource.Logo)}' title="logo" /> <br/> <img src='{!URLFOR($Resource.InvoiceLogo)}' title="logo" /> </td> </tr> </table> <table border="0" cellspacing="0" cellpadding="0" width="100%" id="table1"> <tr> <td> <font face="Arial" > <apex:outputText value="{!Monthly_Cloud_Bill__c.Company_Address__c}" escape="false"/> </font></td> <td width="50%"></td> <td ><font face="Arial">Invoice Date:<apex:OutputField value="{!Monthly_Cloud_Bill__c.Create_Date__c}"/> <br/> Invoice #: {!Monthly_Cloud_Bill__c.Name}<br/> Billing Period: {!Monthly_Cloud_Bill__c.Billing_Period__c} <br/> Customer ID: {!Monthly_Cloud_Bill__c.Account__r.Customer_ID__c} <br/> </font> </td> </tr> </table> <p><b><font face="Arial" color="#000080">Customer Information</font></b></p> <table border="0" width="100%" id="table2"> <tr> <td colspan="3"> <font face="Arial">{!Monthly_Cloud_Bill__c.Account__r.Name} <br/></font> </td> </tr> <tr> <td> <font face="Arial">Attn: {!Monthly_Cloud_Bill__c.Contact__r.Name}<br/> {!Monthly_Cloud_Bill__c.Account__r.BillingStreet}<br/> {!Monthly_Cloud_Bill__c.Account__r.BillingCity}, {!Monthly_Cloud_Bill__c.Account__r.BillingState} {!Monthly_Cloud_Bill__c.Account__r.BillingPostalCode} <br/> {!Monthly_Cloud_Bill__c.Account__r.BillingCountry} <br/> Tel: {!Monthly_Cloud_Bill__c.Contact__r.Name} </font> </td> </tr> </table> <p><b><font color="#000080" face="Arial">Order Description</font></b></p> <table border="1" width="100%" id="table4"> <tr> <td bgcolor="#C0C0C0"><font face="Arial">Product</font></td> <td bgcolor="#C0C0C0" align="center"><font face="Arial">Price</font></td> <td bgcolor="#C0C0C0" align="center"><font face="Arial">Units</font></td> <td bgcolor="#C0C0C0" align="center"><font face="Arial">Amount</font></td> </tr> <tr> <td>Product</td> <td align="center"> {!Monthly_Cloud_Bill__c.Price__c}</td> <td align="center">{!Monthly_Cloud_Bill__c.Net_Usage_For_Billing__c}</td> <td align="center"><apex:OutputField value="{!Monthly_Cloud_Bill__c.Billing_Amount__c}"/></td> </tr> <tr> <td bgcolor="#C0C0C0" align="right" colspan="6"> <font face="Arial"><b>Total Due:</b><apex:OutputField value="{!Monthly_Cloud_Bill__c.Billing_Amount__c}"/></font></td> </tr> </table> <p><b><font color="#000080" face="Arial">Payment Instructions</font></b></p> <table border="0" width="100%" id="table3"> <tr> <td><font face="Arial"> 1. Payment is due in full 30 days from the INVOICE DATE <br/> 2. Overdue payments will be subject to a charge of 1% per month <br/> 3. Payment is accepted by wire transfer, check or credit card: </font> </td> <br/> </tr> <table border="0" width="100%" id="table4"> <!--<tr> <td colspan="3"> </td> </tr> --> <tr> <td> <font face="Arial"><b>Wire transfer instructions:</b><br/> <apex:OutputField value="{!Monthly_Cloud_Bill__c.Wire_transfer_instructions__c}"/> </font> </td> <!-- <td width="1%"></td> --> <td> <font face="Arial"><b>Check payment instructions:</b><br/> <apex:OutputField value="{!Monthly_Cloud_Bill__c.Check_payment_instructions__c}"/> </font> </td> </tr> </table> </table> <hr/> <p align="center"><font face="Arial">If you have any question about this invoice, please contact. <br/> {!Monthly_Cloud_Bill__c.Account__r.Owner.FirstName} {!Monthly_Cloud_Bill__c.Account__r.Owner.LastName}, {!Monthly_Cloud_Bill__c.Account__r.Owner.Phone}, {!Monthly_Cloud_Bill__c.Account__r.Owner.Email} <br/> <br/> <b>Thank You For Your Business!</b> </font></p> </apex:page>
Parent Visualforce:
<apex:page controller="PdfGeneratorController"> <apex:form > <apex:pageBlock title="PDF Input"> <apex:pageBlockButtons > <apex:commandButton action="{!savePdf}" value="Save PDF"/> </apex:pageBlockButtons> <apex:pageMessages /> <iframe height="600px" id="Page" name="InvoicePDF" src="/apex/InvoicePDF2" width="100%"></iframe> </apex:pageBlock> </apex:form> </apex:page>
Many Thanks!
Itay
Hi,
In the Iframe PDF page you can't use standard controller, try using the contoller by getting the record Id in the URL.
Once you did this in the Parent Visualforce: page also pass the same Id in the URL and collect it in any
ID variable(Variable Name is : recordvar) and change the below code
Change the src attribute like below
saravanan, I'm already getting the reocrd id with the string "parentId". I tried placing this insted of "recordvar" in the URL and got:
Error: Unknown property 'PdfGeneratorController.parentId'
Can you elaborate what needs to be changed in the Controller / PDF?
Thanks
<iframe src="/apex/InvoicePDF2?id={!Monthly_Cloud_Bill__c.Id}"></iframe>