Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am wriiting a extension on Case object. There I want to write a save method with my own logic and want this save method should override the standard Save method.

So my code goes like below:

public class MyCaseControllerExt {

    private final Case caseObj;

    // get Case record from the standard controller and putting it in a member variable
    public MyCaseControllerExt (ApexPages.StandardController stdController) {
        this.caseObj = (Case)stdController.getRecord();

    public override PageReference save(){
        // TO DO
        return null;



But, while saving the class, I am getting 1 error :

Save error: MyCaseControllerExt : Method does not override an ancestor method: System.PageReference save()

So my question is how we will override the existing Save method in extension class?

share|improve this question
up vote 12 down vote accepted

You don't use the override keyword in this case, as you aren't extending another class and overriding its methods in a classical object oriented situation. Instead, the Visualforce platform adheres to a contract that it will look for a method in your extension named 'Save' first, and if it doesn't find that it will fallback to the method in the standard controller. This all happens automatically, so all you need to do is define your save method:

public PageReference save(){
    // TO DO
    return null;

share|improve this answer

Your Answer


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.