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

Weird CommandButton behavior

I have a page with two commandbuttons and two action methods in the controller.


The page is built using the OppLineItem standardController and is using the lineitem to derive field to create a custom Object record - an Order in this case.


The buttons are called 'Cancel' and 'SaveOrder'


The Cancel method, is just a pagereference going back to the previous page.


The SaveOrder method captures the data from the inputfields on the page adds them to a new Order record and inserts, and then redirects the user to the Opportunity record. 


Straightforward stuff. The Cancel button works perfectly. The SaveOrder button does nothing but refresh the page (in fact it does this twice, runs through the entire process of setting up the page twice and quits).Not even the debug statement I put in the first line of the method shows up in the debug log.


Here's the weird part. If I switch the action method names - call the Save method 'Cancel', and the Cancel method 'SaveOrder', and then click the Cancel button - the method works!!!!! It creates the record and redirects the user.But if I click the saveOrder button in this case - I get the same behavior - it just refreshes the page.


Here is the relevant code:


    public PageReference cancel()
    	returnPage = new PageReference('/apex/ManageOrders_QC?id='+OLI.OpportunityId).setRedirect(true);
    	return returnPage;
    public PageReference saveOrder()
    	system.debug('Start Save');
        ... other code

        returnPage = new PageReference('/apex/ManageOrders_QC?id='+OLI.OpportunityId).setRedirect(true);
    	return returnPage;

<apex:page standardController="OpportunityLineItem" extensions="Controller_NewManualOrder" >
    <apex:form >
         <apex:pageBlock id="OrderFields">
             <apex:pageBlockButtons id="Buttons">
                <apex:CommandButton id="SaveButton" value="Save Order" action="{!saveOrder}"/>
                <apex:CommandButton id="cancelButton" value="Cancel" action="{!cancel}"/>
                <apex:CommandButton id="returnButton" value="Return to Opportunity" action="{!ReturnToOpp}"/>
            ...PageBlocktable showing fields
    </apex:form >

 What is going on here?






    There might be some system validation errors. Just place <apex:pageMessages/> tag before start of <apex:form> tag.  If there are any exceptions, you will see them here.


   And do you have any field in VF page which has the required attribute as true. In that case, if the value is not populated then the saveorder method will not execute. Just keep an eye on those fields.


Hope this helps





What if you give them both names that aren't "cancel"? Maybe when you click the cancel button, it's using the standardcontroller cancel() method instead? That would imply that there's something in both of your methods that's causing trouble, or possibly elsewhere in your controller. Can you post the rest of your controller code?




Rahul BorgaonkarRahul Borgaonkar



I was strugling with same commandbutton issue. You reply helped me out.


Thanks a ton,