Activity Forums Salesforce® Discussions How many Controllers can be used on a single Salesforce visualforce Page?

  • suniti

    Member
    July 9, 2018 at 9:57 am

    Hi sanjana

    We can have only one controller at a time either it may be "StandardController" or custom Controller.And we can have as many as extensions we want.

    Thank you.

  • Parul

    Member
    September 14, 2018 at 9:25 am

    Hi,

    We can use two controllers on a single salesforce visualforce page. One is controller and for custom functionality, we can use Controller extension.

     

    Thanks.

  • Anjali

    Member
    September 14, 2018 at 9:28 am

    Hi Sanjana,

    Only one controller can be used salesforce. Other than them, Controller extension can be used. There may be more than one Controller extension.

    Example-
    `



    `
    if ExtOne and ExtTwo, both have the method getFoo() then the method of ExtOne will be executed.

  • shariq

    Member
    September 14, 2018 at 12:08 pm

    Hi,

    You can have the two controller functionality in one visualforce page by using standard controller and extension. So in extension you can mention the name of multiple controller from which you want to access the functionality of these controller . For example:-

    VisualForce page:-

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

    Extension Class:-

    ExtOne:-

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

    public String getFoo() {
    return ‘foo-One’;
    }
    }

    ExtTwo:-

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

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

    Hope this helps!

  • Avnish Yadav

    Member
    September 14, 2018 at 12:51 pm

    Hello,

    You can use only one controller at a times but for extensions it depends on you.

    Thanks.

Log In to reply.

Popular Salesforce Blogs