+ Start a Discussion
dwwrightdwwright 

Passing record ID's to Visualforce pages

I've got a page full of input fields that I want to print. To do this, I'm mirroring the page, making modifications so it looks printable, and then using renderas="pdf." I want to have a button on the input page that links directly to the pdf version with the ID of the input record, so that all the fields are filled in on the PDF version for that input record. I've tried to do the following, which links to the pdf page, but doesnt display the information from the record.

 

 

<apex:commandButton style="font-size:14px" action="{!URLFOR($Page.DocPrintPage, MyObject__c.Id)}" value="Print" />

 

Any ideas?

 

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

There's a number of ways to do this.  Here's a couple.

 

You could have an action method in the controller that returns a pagereference to the pdf page, and set the id into the parameters. E.g.

 

 

PageReference gotoPDF() { PageReference result=Page.MyPdfPage; result.getParameters().put(id, MyObject__c.id); result.setRedirect(true); return result; }

 

Or you could do something with the onclick event of the button:

 

 

<apex:commandButton value="Print" onClick="window.location='MyPdfPage?id={!MyObject__c.id}'; return false;" />

 


 

 

 

All Answers

bob_buzzardbob_buzzard

There's a number of ways to do this.  Here's a couple.

 

You could have an action method in the controller that returns a pagereference to the pdf page, and set the id into the parameters. E.g.

 

 

PageReference gotoPDF() { PageReference result=Page.MyPdfPage; result.getParameters().put(id, MyObject__c.id); result.setRedirect(true); return result; }

 

Or you could do something with the onclick event of the button:

 

 

<apex:commandButton value="Print" onClick="window.location='MyPdfPage?id={!MyObject__c.id}'; return false;" />

 


 

 

 

This was selected as the best answer
RONURONU

Hello sir,

   below is my question...please help me out in calling vf page after selecting one record from list... :

 

¢Create a VF page and VF component.
¢In the 1st page, get all the Opportunities in a <apex:selectList>.
¢On select of the Opportunity, go to the 2nd page where you can edit/save selected opportunity's StageName, Close Date.

 

¢Note:

  In the 1st page, use event="onchange"   within <apex:selectList> to go to the 2nd page.

RONURONU
Hello sir,
help me in below question....
any help wud b greatly appreciated...