+ Start a Discussion
Ola BamideleOla Bamidele 

How Many Page Reference Can an Apex Page Have

Hi Gurus, 

I have a visualforce page that has four links to others VF pages via an apex code page. All three links works and redirects when clicked however when I add the fourth link, they all do not work. 

So I was wondering, is their a maxixmum amount of page reference that can be on one apex page? 

If so how can i overcome this issue has I need to have at least 10 page References.

Thanks very much!
Parag Bhatt 10Parag Bhatt 10
Use of PageReference: A PageReference is a reference to an instantiation of a page reference. Among other attributes, PageReferences consist of a URL and a set of query parameter names and values like custom parameters or standard parameters for PageReference created.
PageReference pageRef = new PageReference('/apex/myVfPage');

There are several standard parameters like setRedirect which can be used for hard "reset" of controller state. If you make it false then state of variables in controller is maitained across many VF pages.

If you want to add any custom parameters then you can add them like below
pageRef.getParameters().put('myId', accId); //Assume accId is a variable in class or method
So, overall code will look like
public PageReference redirectToMyVF(Id accId) {
    PageReference myVFPage = new PageReference('/apex/myVFPage')
    myVFPage.getParameters().put('myId', accId);
    return myVFPage;

Quick Answers to your questions:
1. Why we use pagereference as a return type?
- We normally set return type to a PAgeReference when we need user to other VF page. We return "null" if we want user on same page and we normally return "null" in catch blocks.

2. What is the situation to use the pagereference?
- When you want to jump to other VF page when something is clicked and method takes you to new VF page or refreshing current page by doing "return null;"

I Think There is no such limits Page Reference Can an Apex Page .

It will work as expected :)

Please let us know if this will help you.

Parag Bhatt