Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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:

Visualforce

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

Apex

public PageReference gotoClientListPage()
{
    PageReference page = new PageReference('/apex/Setup_Client_List_Layout');
    page.setRedirect(true);
    return page;
}

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

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

share|improve this question
add comment

2 Answers

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.

share|improve this answer
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. :) –  Shoaib Shakeel Feb 6 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? –  Bob Buzzard Feb 6 at 9:45
    
yes. i used following code to create inputField.<apex:inputField value="{!pastDealObject.Name}" required="true" /> –  Shoaib Shakeel Feb 6 at 9:54
1  
I just see the message under the field. Weird. –  Bob Buzzard Feb 6 at 10:01
add comment
up vote 0 down vote accepted

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: http://stackoverflow.com/questions/3090369/disable-validation-of-html5-form-elements

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.