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

Not passing variable to VF page, Kudos offered to anyone who can help.
I am working on a scenario to where a user can preview VF page and then save it to the Contract object in the notes and attachments section.
I'm using two visualforce pages and a class to do this.
The problem is that when I hardcode an actual Contract.id the whole thing works.
But when I try to pass a parameter for the Contract.id the preview fails with the error: "Id value is not valid for the Contract standard controller".
This is the problem line of code:
<iframe height="600px" id="Page" name="Maint Invoice" src="/apex/ContractPDFCreation?id=800S0000000rQfb" width="100%"></iframe>
Below are the two VF pages and class. Pleasse let me know what I can do to pass this parameter successfully??? I will give kudos and solution credit for the person who can get me through this.
The first VF page I call is called "PdfGeneratorTemplate".
This is how the first VF page is executed via a button:
https://cs1.salesforce.com/apex/PdfGeneratorTemplate?id={!Contract.Id}
Note the hardcoded Contract.id in the following code, this is what needs fixed:
<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="Maint Invoice" src="/apex/ContractPDFCreation?id=800S0000000rQfb" width="100%"></iframe> </apex:pageBlock> </apex:form> </apex:page>
This is the main VF page that renders a pdf:
<apex:page standardController="Contract" showHeader="false" renderas="pdf"> <table border="0" cellspacing="0" cellpadding="0" width="100%" id="table1"> <tr> <td> <img src='{!URLFOR($Resource.APSLogoContract)}' title="logo" /> </td> <td align="center" style="font-size:20px;"><font face="Arial"> <b>INVOICE</b></font> <table border="1" cellspacing="0" cellpadding="1" width="100%" id="table77"> <tr> <td bgcolor="#d7dee9"> <font face="Arial" style="font-size:13px;">Date: </font> </td> <td> <font face="Arial" style="font-size:13px;"> <apex:outputText value="{0,date,MM'/'dd'/'yyyy}"> <apex:param value="{!contract.WF_Invoice_Date__c}" /> </apex:outputText> </font> </td> </tr> <tr> <td bgcolor="#d7dee9"> <font face="Arial" style="font-size:13px;">Due: </font> </td> <td> <font face="Arial" style="font-size:13px;">Due Upon Receipt</font> </td> </tr> </table> </td> </tr> </table> <br/> <table border="0" cellspacing="0" cellpadding="1" width="100%" id="table2"> <tr> <td colspan="2" style="font-size:13px;"> <font face="Arial">BarbaraG@aps.us <br/><br/></font> </td> </tr> <tr> <td style="font-size:13px;"> <font face="Arial">Bill To:<br/><br/> {!Contract.Account.Name}<br/> {!Contract.Account.BillingStreet}<br/> {!Contract.Account.BillingCity}. {!Contract.Account.BillingState} {!Contract.Account.BillingPostalCode} </font> </td> <td width="20%"></td> <td style="font-size:13px;"> <font face="Arial">Ship To:<br/><br/> {!Contract.Account.Name}<br/> {!Contract.Account.ShippingStreet}<br/> {!Contract.Account.ShippingCity}. {!Contract.Account.BillingState} {!Contract.Account.ShippingPostalCode} </font> </td> </tr> </table> <br/><br/><br/> <table border="1" cellspacing="0" cellpadding="1" width="85%" id="table15"> <tr> <td bgcolor="#d7dee9" align="center"><font face="Arial">Contract Number</font></td> <td bgcolor="#d7dee9" align="center"><font face="Arial">Product</font></td> <td bgcolor="#d7dee9" align="center"><font face="Arial">Term</font></td> <td bgcolor="#d7dee9" align="center"><font face="Arial">Invoice Amount</font></td> </tr> <tr> <td align="center"><font face="Arial"> {!Contract.ContractNumber} </font> </td> <td align="center"><font face="Arial"> Maintenance </font> </td> <td align="center"><font face="Arial"> <apex:outputText value="{0,date,MM'/'dd'/'yyyy}"> <apex:param value="{!contract.startdate}" /> </apex:outputText>-<apex:outputText value="{0,date,MM'/'dd'/'yyyy}"> <apex:param value="{!Contract.Contract_End_Date__c}" /> </apex:outputText> </font> </td> <td align="center"><font face="Arial"> <apex:outputText value="{0,number,$#,###,###.00}"> <apex:param value="{!Contract.Total_Maintenance_Price__c}" /> </apex:outputText> </font> </td> </tr> </table> <br/><br/> <table border="1" style="border-color: #3B5E91" cellspacing="0" cellpadding="1" width="100%" id="table4"> <tr> <td bgcolor="#d7dee9" align="left"><font face="Arial">Product(s) Covered</font></td> <td bgcolor="#d7dee9" align="center"><font face="Arial">Quantity</font></td> </tr> <tr> <apex:repeat value="{!Contract.Service_Contract_Line_Items__r}" var="line"> <tr> <td align="left">{!line.Product_LU__r.name}</td> <td align="right">{!(ROUND(line.Quantity__c,0))}</td> </tr> </apex:repeat> </tr> </table> <br/><br/> <table border="1" cellspacing="0" cellpadding="1" width="65%" id="table3"> <tr> <td bgcolor="#d7dee9" align="left"><font face="Arial">Please Note Our Remit To Address</font></td> </tr> <tr> <td><font face="Arial"> Advanced Public Safety, Inc.<br/> PO Box 535208<br/> Atlanta, GA 30353-5208<br/><br/> Wire Instructions: Wells Fargo Bank<br/> ABA#: 121000248 Account #: 412-1360267 </font> </td> </tr> </table> <br/> </apex:page>
This is the class code:
public with sharing class PdfGeneratorController { String parentId = ApexPages.currentPage().getParameters().get('id'); Contract c = [SELECT id, ContractNumber from Contract WHERE Id = :parentId]; String ContractNumber = c.ContractNumber; public PageReference savePdf() { //PageReference pdf = Page.PdfGeneratorTemplate; PageReference pdf = Page.ContractPDFCreation; // 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 = 'Invoice - ' + ContractNumber + '.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); } }
Please let me know how to pass the Contract.id into the first VF page properly so I can be done with this.
Thank you,
Steve Laycock
I was the way I was referencing the Contract.id.
This is what I had to do in the class:
Thank you it is the Public Contract cc...... that I went wrong with. My initial try I don't think I made it public.
Steve