I am trying to build a controller extension for the Opportunity standard controller.

According to documentation and stackexchange I ought to be able to override the Save() action in the controller extension. I have a VF page that is embedded in the standard Opportunity layout and a save() method in the controller extension, but the save() method in my controller extension never gets called.

What am I doing wrong?

The VF page - embedded in the standard Opportunity layout:

<apex:page standardController="Opportunity" extensions="TestExtension" showHeader="false" >

The controller extension class - I get the constructor debug message, but not the one from save():

public without sharing class TestExtension {

    ApexPages.StandardController stdController = null;

    public TestExtension(ApexPages.StandardController stdController) {
        this.stdController = stdController;
        System.debug('==== TestExtension: TestExtension() ====');
    public PageReference save() {       
        System.debug('==== TestExtension: save() ====');
        // do some stuff
        Pagereference ref = stdController.save();
        // some more stuff
        // give control back to standard controller
        return ref;
  • You can't inject a single method override, but instead have to override one of the standard actions with a complete replacement page. Then your method will be called. Can't find a good e.g. Trailhead on this, but hopefully someone else will.
    – Keith C
    Nov 21, 2021 at 20:26
  • Keith: yes I could probably put a Save button in my extension page and trap the user into pressing it instead of the parent window Save button. But I definitely do not want to replace the entire standard page with a VF page, not least because I would lose the comfort of (no code!!!) modification of the Layout. The terms extension and override used in the documentation in this context seem to be not more than a pretty ludicrous make-believe.
    – willeg
    Nov 21, 2021 at 21:04

1 Answer 1


The examples you are referencing only apply if your controller extension is managing the entire page. You cannot change the standard save behavior for an object by embedding a Visualforce page in its layout; page embedding is not a "hook" into the save process.

Your only direct solution is overriding the entire action with a Visualforce page or Lightning (Aura) component, which requires you to reimplement the page layout. It's an expensive, clumsy, inflexible solution that I usually recommend against.

In most cases, a better solution is to rethink your overall objective such that you can achieve it with some combination of

  • Quick Actions, for streamlining create operations with prepopulated fields.
  • Screen Flows, for interactive wizard-style UIs.
  • Apex triggers or record-save flows, for non-UI automation.
  • Very well explained.
    – Keith C
    Nov 22, 2021 at 9:30
  • I am going to rethink my problem in the light of your suggestions. If I then still don't see how to solve my problem, I will come back.
    – willeg
    Nov 24, 2021 at 18:16
  • 1
    ευρηκα ηδη: this question and my earlier one here were posted in the context made clear in the latter. And the solution is: as simple as a record-triggered (after update) Flow.
    – willeg
    Nov 27, 2021 at 12:00

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.