When cancel button is clicked in visualforce page, it has to redirect to home page.Instead I'm getting the same visualforce page.Kindly help.

public PageReference cancel()
    return null;

2 Answers 2


Method -

Using html-5 in doctype in visualforce page means you should use html-formnovalidate and immediate in cancel button. For example

<apex:commandButton action="{!cancel}" value="Cancel" immediate="true" 
                    html-formnovalidate="formnovalidate" />

I can see you have returned "null" from "page reference method" used for cancel. When you return null salesforce keeps redirects to same page. That is the reason when you are using this method, salesforce is keeping you at same page.

You must log in to answer this question.

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