Header

Sunday, August 14, 2011

Visualforce Page Redirection

I needed a button in a standard page of a custom object to do some logic when pressed. Initially, I found out that this could be done through a Global Apex Class. So, I started developing using this approach but I had a hard time passing some parameters to the class from the page. I managed to find some workarounds to address the issue, however, it seemed that I was doing a lot just to make it work. With this, I decided to find another alternative to do the functionality. I realized that I could redirect to a Visualforce page using the button and add method in the controller to do the logic. This time, my problem is that the page redirection does not work after the method is executed in the constructor. After some researching on the cause of this, it turned out that the constructor does not know what to do with the pagereference object it got from the method. As a result, no page redirection happens. To address this issue, you need to call the method in the action parameter of the visualforce page instead of the constructor.

Here's an example:

<apex:page controller="SampleController" action="{!sampleLogicMethodWithRedirection}">


No comments:

Post a Comment