Yes we can. In that case you need to override the new and Edit button with a VF page and then in the extension class you can write your own save method.
Mr T-Force is correct. Be careful though as using a standardController together with an extension method called "save()" can cause problems since the standardController also includes a method called "save()". If you're seeing strange behaviour rather call your save method some like "saveAccount()".
I don't think so that it will really happen.Once you defined a method in the extension having same name as your standard controller have . In that case this will be called from the extension class.
like:
<apex:page standardController="Account" extensions="MyExtension">
<apex:form>
<apex:commandButton action="{!save}" value="Save" />
<apex:commandButton action="{!cancel}" value="Cancel" /> </apex:form>
</apex:page>
public class MyExtension
{
public MyExtension(ApexPages.StandardController controller){}
public PageReference save()
{
System.debug('Save button overrided');
}
}
Now in this scenerio :
Save will be called from the class, But the cancel button will call the StandardController cancel method, as class doesn't have any cancel method.
Yes we can. In that case you need to override the new and Edit button with a VF page and then in the extension class you can write your own save method.
Like :
<apex:page standardController="Account" extensions="MyExtension">
<apex:form>
<apex:commandButton action="{!save}" value="Save" />
</apex:form>
</apex:page>
public class MyExtension
{
public MyExtension(ApexPages.StandardController controller){}
public PageReference save()
{
System.debug('Save button overrided');
}
}
Hello,
Mr T-Force is correct. Be careful though as using a standardController together with an extension method called "save()" can cause problems since the standardController also includes a method called "save()". If you're seeing strange behaviour rather call your save method some like "saveAccount()".
Wes
Hi Wes,
I don't think so that it will really happen.Once you defined a method in the extension having same name as your standard controller have . In that case this will be called from the extension class.
like:
Now in this scenerio :
Save will be called from the class, But the cancel button will call the StandardController cancel method, as class doesn't have any cancel method.
Indeed :) This was a bug for a long time but it might be resolved now - thought I'd flag it up just in case.