function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
eliotstockeliotstock 

custom controller: validation errors on cancel

Hi there.

 

I can't figure out how to circumvent validation when clicking a cancel button on a Visualforce page that uses a custom controller.

 

The page has this button:

 

 

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

 

And the cancel method in the controller does this:

 

 

public PageReference cancel() { System.debug('cancel()'); String accountId = ApexPages.currentPage().getParameters().get('AccountId'); return new PageReference(accountId); }

 

 but I never see my debug. Instead I see all the required fields on the page with red boxes ("Error: You must enter a value"). Any help would be appreciated.

 

Thanks.

 

 

Best Answer chosen by Admin (Salesforce Developers) 
JimRaeJimRae

on the commandbutton add the immediate=true parameter.

 

 

 

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

 

 

 

All Answers

JimRaeJimRae

on the commandbutton add the immediate=true parameter.

 

 

 

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

 

 

 

This was selected as the best answer
eliotstockeliotstock
Thanks a million.