1

Whenever a cancel button is clicked I want to take the user to the previous page.

SO here I am calling the JavaScript function but it is throwing an error Formula Expression is required on the action attributes

Page :

<apex:page standardController="Account">
<apex:includeScript value="/soap/ajax/35.0/connection.js" />
    <script type="text/javascript">
    function goBack() {
    window.history.back();
}
</script>
<apex:commandButton action="goBack()" value="Cancel" immediate="true" /> <!-- I added immediate = true to avoid validations other wise it is asking to eneter required fields -->

</apex:page>
  • Just use a vanilla html button instead? – Adrian Larson Aug 9 '17 at 20:21
3

Use onclick function instead of action, as action looks for methods of the Controller.

<apex:page standardController="Account">
<apex:includeScript value="/soap/ajax/35.0/connection.js" />
    <script type="text/javascript">
    function goBack() {
    window.history.back();
}
</script>
<apex:commandButton onclick="javascript:goBack()" value="Cancel" immediate="true" /> 

</apex:page>

Or, just in case if you want to use standard Controller's cancel then use

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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