0

1) If I have a standard controller and two extensions Ext1 and Ext2 and if both Ext1 and Ext2 have the save method, then whose save method will be called Standard controller's, Ext1's or Ext2's?

<apex:page standardController=”Account”
extensions=”Ext1,Ext2”>

2) Similarly if I have a custom controller and two extensions Ext1 and Ext2 and if custom controller and both the extensions have the save method, then whose save method will be called custom controller's, Ext1's or Ext2's?

<apex:page controller=”CustomController”
    extensions=”Ext1,Ext2”>

Please clarify.

3

According to documentation save method from Ext1 would be called in both situations.

(...) Overrides are defined by whichever methods are defined in the “leftmost” extension, or, the extension that is first in the comma-separated list. (...)

You can easily check it by yourself creating 3 classes and visualforce page, for example:

Class 1

public class TestCont1 {
    private String myTxt = '1';

    public String getMyTxt() {
        return myTxt;
    }

    public void changeTxt() {
        myTxt += '1';
    }
}

Class 2

public class TestCont2 {
    private String myTxt = '2';

    public TestCont2(TestCont1 tc) {

    }
    public String getMyTxt() {
        return myTxt;
    }

    public void changeTxt() {
        myTxt += '2';
    }
}

Class 3

public class TestCont3 {
    private String myTxt = '3';

    public TestCont3(TestCont1 tc) {

    }
    public String getMyTxt() {
        return myTxt;
    }

    public void changeTxt() {
        myTxt += '3';
    }
}

And VF page:

<apex:page controller="TestCont1" extensions="TestCont2, TestCont3">
    <apex:outputText value="{!myTxt}"/>
    <apex:form>
        <apex:commandButton action="{!changeTxt}" value="Change sth"/>
    </apex:form>
</apex:page>

You will see on page that '2' is displayed and after each click on Change button '2' is added to the string.

| improve this answer | |
1

Ans(1) In first case ext1's save method will be called.
Ans(2) In second case ext1's save method will be called.
Actually controller class is parent and remaining classes are child, when your page get loaded all constructor related to these 3 classes will invoke, but save method of parent class is overided in child classes, both child classes having parameterize constructors and having parent class object in parameter, and by default first child class invoke save method by overriding parent save method.

| improve this answer | |

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.