Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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

1 Answer 1

up vote 7 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

 
discard

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.