i am creating a custom vf page without any standard controller. And i need to implement cancel button functionality. following is the code i am using:


<apex:commandbutton value="Cancel" action="{!gotoClientListPage}" immediate="true"/>


public PageReference gotoClientListPage()
    PageReference page = new PageReference('/apex/Setup_Client_List_Layout');
    return page;

But when i click on this button following error occurs: Image

Can anyone help me solve this error. Thnx in advance.

4 Answers 4


Setting the immediate="true" attribute will bypass any Salesforce validation and view state updating. The fact that you are seeing fields marked as required suggests that there is some custom client side validation being carried out, through JavaScript for example (especially as the error message popout isn't standard Salesforce).

You can avoid the JavaScript validation by setting a JavaScript variable, e.g. cancelling=true, via an onclick handler for the button and then changing the custom validation to check if cancelling is set to true and if it is, skip the validation.

  • 1
    Actualy, this is salesforce standard error message. It appears if inputField is explicity marked required by setting required=true. But thanx for illuminating me that problem is on client side validation. :) Commented Feb 6, 2014 at 9:25
  • I don't recall seeing the error message presented in a popout as it is in this case. Is this on a regular page? Commented Feb 6, 2014 at 9:45
  • yes. i used following code to create inputField.<apex:inputField value="{!pastDealObject.Name}" required="true" /> Commented Feb 6, 2014 at 9:54
  • 1
    I just see the message under the field. Weird. Commented Feb 6, 2014 at 10:01

While applying cancel operation visualforce you should stop the form validation.Use below any one methods to stop the form validation based on your requirements.

Method 1:

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" />

Method 2:

you should use immediate key word only need for stopping form validation. For Example

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

This problem is being caused by browsers due to HTML 5 form validation. So i just added novalidate attribute to my form elements and it worked fine. For more information: https://stackoverflow.com/questions/3090369/disable-validation-of-html5-form-elements


try this in case it is custom controller and not using standard cancel action the this:

 oncomplete="javascript:window.open('/{!$CurrentPage.parameters.opportunityId}', '_parent');" 

You must log in to answer this question.

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