function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
KaityKaity 

Controller and Extensions:

Hi,

Can some one help me on this by explaining the reasons:

 

Given the following Force.com page markup and assuming the controller and each extension include an action method named “go,” which class method will be invoked when the user clicks on the commandButton?
A. theController
B. ext1
C. ext2
D. ext3

 

-Kaity

Best Answer chosen by Admin (Salesforce Developers) 
asish1989asish1989

controller method is invoked,If same method is not there in controller then It will go to extension.

 

 

For your reference...

Multiple controller extensions can be defined for a single page through a comma-separated list. This allows for overrides of methods with the same name. For example, if the following page exists:

<apex:page standardController="Account" 
    extensions="ExtOne,ExtTwo" showHeader="false"> <apex:outputText value="{!foo}" /> </apex:page>

with the following extensions:

public class ExtOne {
    public ExtOne(ApexPages.StandardController acon) { }

    public String getFoo() {
        return 'foo-One';
    }
}
public class ExtTwo {
    public ExtTwo(ApexPages.StandardController acon) { }

    public String getFoo() {
        return 'foo-Two';
    }
}

The value of the<apex:outputText>component renders asfoo-One. Overrides are defined by whichever methods are defined in the “leftmost” extension, or, the extension that is first in the comma-separated list. Thus, thegetFoomethod ofExtOneis overriding the method ofExtTwo.

All Answers

asish1989asish1989

controller method is invoked,If same method is not there in controller then It will go to extension.

 

 

For your reference...

Multiple controller extensions can be defined for a single page through a comma-separated list. This allows for overrides of methods with the same name. For example, if the following page exists:

<apex:page standardController="Account" 
    extensions="ExtOne,ExtTwo" showHeader="false"> <apex:outputText value="{!foo}" /> </apex:page>

with the following extensions:

public class ExtOne {
    public ExtOne(ApexPages.StandardController acon) { }

    public String getFoo() {
        return 'foo-One';
    }
}
public class ExtTwo {
    public ExtTwo(ApexPages.StandardController acon) { }

    public String getFoo() {
        return 'foo-Two';
    }
}

The value of the<apex:outputText>component renders asfoo-One. Overrides are defined by whichever methods are defined in the “leftmost” extension, or, the extension that is first in the comma-separated list. Thus, thegetFoomethod ofExtOneis overriding the method ofExtTwo.

This was selected as the best answer
KaityKaity

Nice analysis. True Mentor!

KaityKaity

What is the maximum limit of using extensions? I've used 7, but Apex runEngine didn't throw any error?

 

-Kaity

Laxman RaoLaxman Rao

There is no such limit exists, you can use any number or extension but controller should be one.

fgwarb_devfgwarb_dev
For clarification the accepted answer here contradicts the public developer page with this sample question (currently located here: http://certification.salesforce.com/developers)

The VF markup documented on that page is:
[code]
<apex:page controller="theController" extensions="ext1, ext2, ext3">
<apex:form>
<apex:commandButton value="Go" action="{!go}" rerender="out" />
<apex:outputPanel id="out">{!output}</apex:outputPanel>
</apex:form>
</apex:page>
[/code]


The sfdc.com page states that B is the correct answer, but I can't tell why... who is right?  This thread or the SFDC public page?  If the SFDC public page, why?