1

I have a controller that return PageReferences. This are all relative. But in some cases, I need to return back full URLs.

Something like: http://www.google.com

This works but, I want to be 100% sure how PageReference makes the decision to be relative or absolute. How does it?

1 Answer 1

7

The official doc says that PageReferences could manage both partial an absolute without problem.

PageReference pageRef = new PageReference('partialURL');

Creates a PageReference to any page that is hosted on the Force.com platform. For example, setting 'partialURL' to '/apex/HelloWorld' refers to the Visualforce page located at http://mySalesforceInstance/apex/HelloWorld. Likewise, setting 'partialURL' to '/' + 'recordID' refers to the detail page for the specified record.

This syntax is less preferable for referencing other Visualforce pages than Page.existingPageName because the PageReference is constructed at runtime, rather than referenced at compile time. Runtime references are not available to the referential integrity system. Consequently, the platform doesn't recognize that this controller or controller extension is dependent on the existence of the specified page and won't issue an error message to prevent user deletion of the page.

PageReference pageRef = new PageReference('fullURL');

Creates a PageReference for an external URL. For example:

PageReference pageRef = new PageReference('http://www.google.com');

Finally, no matter how Apex manage PageReference. The Url will be analyzed and the browser will request it properly.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .