How to redirect to a different VF page from the constructor with parameters in Salesforce?

Sample Code:

Apex Class:

public with sharing class SampleClass{

    public SampleClass(){
    public PageReference doRedirect(){
        String userId = UserInfo.getUserId();
        PageReference pageRef = new PageReference('/apex/TestPage2');
        return pageRef;

VF Page:

<apex:page controller="SampleClass" action="{!doRedirect}">
	This is your new Page

Leave a Reply