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
VamsiVamsi 

Hi, if a controller has a series of extensions then which extension will execute first can any one please explain ...?

Best Answer chosen by Vamsi
Ganesh HembramGanesh Hembram
HI Vamshi,
Based on your formula field {! } it will execute the corresponding extension. If both the extension having same method name then it will execute first extension. Below is the example 

If both extension having same method, whichever methods are defined in the “leftmost” extension, or, the extension that is first in the comma-separated list will execute first.

Apex Code :
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';
        }
   }

VF Code:
 <apex:page standardController="Account" extensions="ExtOne,ExtTwo" showHeader="false">
    <apex:outputText value="{!foo}"/>  //This formula field will call first foo() i.e ExtOne
</apex:page>



If both having different method then it will execute based on formula {! } which method you are calling

Apex Code :
public class OneExt {
    public OneExt(ApexPages.StandardController controller) { }
    
    public String getFood() {
        return 'OneExt';
    }
}

public class TwoExt {

    public TwoExt(ApexPages.StandardController controller) {}
    
    public String getFoo() {
        return 'TwoExt';
    }

}

VF Code :
<apex:page standardController="Account" extensions="ExtOne,ExtTwo" showHeader="false">
    <apex:outputText value="{!foo}"/>  //This formula field will call second foo() i.e TwoExt
</apex:page>

All Answers

Prashanth KapparapuPrashanth Kapparapu
First one from left to right!!
Ganesh HembramGanesh Hembram
HI Vamshi,
Based on your formula field {! } it will execute the corresponding extension. If both the extension having same method name then it will execute first extension. Below is the example 

If both extension having same method, whichever methods are defined in the “leftmost” extension, or, the extension that is first in the comma-separated list will execute first.

Apex Code :
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';
        }
   }

VF Code:
 <apex:page standardController="Account" extensions="ExtOne,ExtTwo" showHeader="false">
    <apex:outputText value="{!foo}"/>  //This formula field will call first foo() i.e ExtOne
</apex:page>



If both having different method then it will execute based on formula {! } which method you are calling

Apex Code :
public class OneExt {
    public OneExt(ApexPages.StandardController controller) { }
    
    public String getFood() {
        return 'OneExt';
    }
}

public class TwoExt {

    public TwoExt(ApexPages.StandardController controller) {}
    
    public String getFoo() {
        return 'TwoExt';
    }

}

VF Code :
<apex:page standardController="Account" extensions="ExtOne,ExtTwo" showHeader="false">
    <apex:outputText value="{!foo}"/>  //This formula field will call second foo() i.e TwoExt
</apex:page>
This was selected as the best answer
VamsiVamsi
Thanks Ganesh ..!!!