function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Vegaln1Vegaln1 

Can I call another VF page from a VF page ?

I have a VF page ( VF page1)  that is using a extention Controller to display case history. I have another VF page ( VF page2 )  that will render a printable version of the Case history. I would like to add a command button ( <apex:commandButton) to allow VF page1 to call VF Page2. Is this possible or is there a better way to acomplish this?

 

Regards,

Best Answer chosen by Admin (Salesforce Developers) 
IanRIanR

Sorry, just realised that the first page should, of course, reference a standardController, not a controller...

 

 

i.e.

 

 <apex:page standardController="Case" extensions="MyExtension" >

 

 

Regards,

Ian Randall 

All Answers

IanRIanR

Bind your button to a method that returns the PageReference for your second page...

 

e.g.

 

<apex:form> <apex:commandButton action="{!NavigateToPrintablePage}" value="Printable Page" /> </apex:form>

 

 

then in the controller for VF1,

 

 

public PageReference NavigateToPrintablePage() { PageReference pageRef = new PageReference('/apex/vf2'); return pageRef; }

 

Of course, you can use parameters to pass the Id of the Case to be rendered in your second page...

 

 

Hope this helps :)

Vegaln1Vegaln1

IanR:  Thank you for the suggestion.

 

Regards,

 

Vegaln1Vegaln1

Ian... Question please.... in your example how would I pass the case Id?

 

Thanks.

IanRIanR

OK,

 

So I'm assuming you are passing an instance of the ApexPages.StandardController object in your extension constructor - you need to set your Controller to be 'Case' in your first Page

 

<apex:page controller="Case" extensions="MyExtension" > </apex:page>

 

 

then in your extension class:

 

class MyExtension { private Case thisCase; public MyExtension(ApexPages.StandardController stdController) { thisCase = (Case)stdController.getRecord(); } public PageReference NavigateToPrintablePage() { PageReference pageRef = new PageReference('/apex/vf2'); pageRef.getParemeters().put('caseId', thisCase.Id); return pageRef; } }

 

so you have put a parameter called 'caseId' into the page reference.

 

Then in the controller for your second page, you can use ApexPages.currentPage().getParameters().get('caseId') to retrieve the Case Id, which you can use to query the database and build your printable view,

 

 

HTH :)

 

Ian

IanRIanR

Sorry, just realised that the first page should, of course, reference a standardController, not a controller...

 

 

i.e.

 

 <apex:page standardController="Case" extensions="MyExtension" >

 

 

Regards,

Ian Randall 

This was selected as the best answer
Vegaln1Vegaln1

Thanks Ian.... Got it now.

 

Regards,