2

I have a visualforce page embedded in an iframe into another visualforce page (see below), the iframed pages is a PDF. When I click the custom button preview the PDF, 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}

Parent

    <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>

Iframe

<apex:page standardController="Monthly_Cloud_Bill__c" showHeader="false" renderas="pdf"> 

<table border="0" cellspacing="0" cellpadding="0" width="100%" id="table1">
<tr>
    <td>
        <img src='{!URLFOR($Resource.Logo)}' title="logo" />
    </td>
    <td  align="right"><font face="Arial" >
    <b>Quote  for {!Monthly_Cloud_Bill__c.account__r.Name}</b></font><br/>
    </td>


</tr>

<hr/>

</table>
<table border="0" cellspacing="0" cellpadding="0" width="100%" id="table1">
<tr>    <td><font face="Arial" >
        {!$Organization.Name}<br/>
        {!$Organization.Street}<br/>
        {!$Organization.PostalCode} {!$Organization.City}<br/>
        {!$Organization.Country}<br/>
        </font></td> 
        <td width="60%">&nbsp;</td>
   <td ><font face="Arial">Invoice number: {!Monthly_Cloud_Bill__c.Name}

        <br/>
        Invoice Date:<apex:OutputField value="{!Monthly_Cloud_Bill__c.CreatedDate}"/><br/>    
       </font>
     </td>
</tr>
</table>
<br/>
<hr/>
<p><b><font face="Arial" color="#000080">Address Information</font></b></p>

<table border="0" width="100%" id="table2">
<tr>
       <td colspan="3">
           <font face="Arial">Account name: {!Monthly_Cloud_Bill__c.Account__r.Name} <br/><br/></font>
       </td>
</tr>
<tr>
       <td>          
           <font face="Arial">Bill To:<br/>
                             {!Monthly_Cloud_Bill__c.Account__r.BillingStreet}<br/>
                             {!Monthly_Cloud_Bill__c.Account__r.BillingPostalCode} {!Monthly_Cloud_Bill__c.Account__r.BillingCity}
           </font>
        </td>
        <td width="50%"></td>
        <td >
           <font face="Arial">Ship To:<br/>
                              {!Monthly_Cloud_Bill__c.Account__r.ShippingStreet}<br/>
                              {!Monthly_Cloud_Bill__c.Account__r.ShippingPostalCode} {!Monthly_Cloud_Bill__c.Account__r.ShippingCity}
           </font>
        </td>
</tr>    
</table>
<br/>
<hr/>
<p><b><font color="#000080" face="Arial">Order Description</font></b></p>
<table border="0" width="100%" id="table4">
<tr>
       <td bgcolor="#C0C0C0"><font face="Arial">Product</font></td>
       <td bgcolor="#C0C0C0"><font face="Arial">Price</font></td>
       <td bgcolor="#C0C0C0"><font face="Arial">Amount</font></td>       
   <!--    <td bgcolor="#C0C0C0"><font face="Arial">Total Price</font></td> -->
</tr>
<tr>

             <td>Product1</td>
             <td>{!Monthly_Cloud_Bill__c.Billing_Amount__c}</td>  
             <td>{!Monthly_Cloud_Bill__c.Amount__c}</td>             
     <!--        <td><apex:OutputField value="{!line.TotalPrice}"/></td> -->
          </tr>


<tr>
       <td bgcolor="#C0C0C0" align="right" colspan="6">
       <font face="Arial"><b>Total Due:</b><apex:OutputField value="{!Monthly_Cloud_Bill__c.Net_Usage_For_Billing__c}"/></font></td>
</tr>
</table>
<br/>
<hr/>
<p><b><font color="#000080" face="Arial">Payment Instructions</font></b></p>
<table border="0" width="100%" id="table3">
<tr>
        <td><font face="Arial">

              Start date: <!-- <apex:OutputField value="{!Opportunity.QuoteBeginDate__c}"/><br/> -->

            </font>
        </td>

</tr>
</table>
<br/>
<!--<p><font face="Arial">{!Opportunity.Conditions__c}</font></p> -->
<br/>
<hr/>
<table width="100%" id="table5">
<tr>
   <td width="50%"><b>{!$Organization.Name}</b></td>
</tr>
<tr>
   <td width="50%">&nbsp;</td>
   <td width="50%">&nbsp;</td>
</tr>
<tr>
   <td width="50%">Signature<hr color="black" size="1"/></td>
   <td width="50%">Signature<hr color="black" size="1"/></td>
</tr>
<tr>
   <td width="50%">Name<hr color="black" size="1"/></td>
   <td width="50%">Name<hr color="black" size="1"/></td>
</tr>
<tr>
   <td width="50%">Title<hr color="black" size="1"/></td>
   <td width="50%">Title<hr color="black" size="1"/></td>
</tr>
<tr>
   <td width="50%">Date<hr color="black" size="1"/></td>
   <td width="50%">Date<hr color="black" size="1"/></td>
</tr>
</table>
<p>&nbsp;</p>
<hr/>
<p align="center"><font face="Arial"><i>Copyright {!$Organization.Name}.</i></font></p>
</apex:page>

Class:

public with sharing class PdfGeneratorController {


  // public ID parentId {get;set;}
  //public String pdfName {get;set;}
  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);

  }


}
2

The reason might be that you have no property declared with the name 'mcb'. I would recommend adding a property like this:

public Monthly_Cloud_Bill__c mcb { 
      get{
          if(mcb == null){
              mcb = [SELECT Account__r.Id, Account__r.Name from Monthly_Cloud_Bill__c WHERE Id = :parentId]; // missing parentId parameter should be handled
          }
          return mcb;
      }
      set;
}

Then you can implement the ifram like so:

<iframe height="600px" id="Page" name="InvoicePDF" src="/apex/InvoicePDF2?id={!mcb.Id}" width="100%"></iframe>
| improve this answer | |
2

Pass the Id of the Monthly_Cloud_Bill__c record in that you would like to display like:

<iframe height="600px" id="Page" name="InvoicePDF" src="/apex/InvoicePDF2?id={!monthlyCloudBillId}" width="100%"></iframe>

The standard controller your using in the inner page always looks for the id parameter to have a record to work with. The record id needs to be available as a property in the controller of the outer page.

| improve this answer | |
  • Hi @h9nry, I added the outer page controller, which already fetches the record ID. can I use the same controller to pass the id into the Iframe visualforce? – Itay B May 28 '13 at 7:20
  • yes just use the record id from the outer controller and pass it as the id parameter for the page called by the iframe. so in my example you would have a property monthlyCloudBillId in the outer page's controller and you pass that directly on to the id param of the iframes src. – h9nry May 29 '13 at 7:34
  • I'm getting: Unknown property 'PdfGeneratorController.monthly_Cloud_Bill__c'... I tried placing src="/apex/InvoicePDF2?id={!monthly_Cloud_Bill__c.Id}") – Itay B May 29 '13 at 9:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.