I would like to know if its possible to share a common extension class across multiple Visualforce Pages which use different standard Controllers.

For Eg., I've VF_A Page which overrides default Contact Page and VF_B Page which overrides Lead Page. I need a common functionality to be implemented in both Contact and Lead Pages. Right now, I've two extensions Ext_A ad Ext_B to implement the same functionality.

What I'm looking for is, if there is a way to use a single Extension Ext_A_B to be used in both the pages. Its possible to use the same extension by finding out the Object.getKeyPrefix().

I'm not sure if its the right way to proceed? Or is there any other way to go about it?


yes it is possible since standard controller extensions require just a constructor with a standard controller as a param

public class Ext_A_B {

    public Ext_A_B(ApexPages.StandardController controller){

        sObjectType sot = controller.getRecord().getsObjectType();

        if (sot == Lead.sObjectType){
           // LEAD LOGIC
        else if (sot == Contact.sObjectType){
           // CONTACT LOGIC


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.