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
karimulla salesforcekarimulla salesforce 

include page Functionality

Can we use the mutiple controllers or multiple clases when iam using the <apex:inculde page />
Can we use apex:include  multiple controller,

Ex: page1
 <apex:page  controller="class1">

 <apex:include pageName="page2"/>
</apex:page>

Page:2

<apex:page  controller="class2">

 <apex:inputext />
</apex:page>

Thanks in advance ...!
 
Khan AnasKhan Anas (Salesforce Developers) 
Hi Karimulla,

Greetings to you!

Yes, you can use different controllers. Please check the below code:

Visualforce 1: Vf1
<apex:page controller="Vf1C">
    <apex:include pageName="Vf2"/>
    <apex:form >
        <apex:pageBlock id="pbAccountDetails">
            <apex:pageBlockSection columns="1" collapsible="false">
                <apex:pageBlockTable value="{!account}" var="ac">
                    <apex:column value="{!ac.Name}" /> 
                    <apex:column value="{!ac.Phone}" />
                </apex:pageBlockTable>
            </apex:pageBlockSection>    
        </apex:pageBlock>
    </apex:form>
</apex:page>

Controller 1:
public class Vf1C {
    
    public List<Account> account{get;set;}
    
    public Vf1C(){
        account = [SELECT Id, Name, Phone FROM Account LIMIT 10];
    }
}

Visualforce 2: Vf2
<apex:page controller="Vf2C" >
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save" />
            </apex:pageBlockButtons>
            <apex:pageBlockSection >
                <apex:inputField value="{!acc.Name}"/>
                <apex:inputField value="{!acc.Phone}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Controller 2:
public class Vf2C {

    public Account acc {get;set;}
    
    public Vf2C(){
        acc = new Account();
    }
    
    public void save(){
        INSERT acc;
        acc = new Account();
    }
}

Refer this link also: https://salesforce.stackexchange.com/questions/79815/visualforce-page-apexinclude-issue

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
karimulla salesforcekarimulla salesforce
Hi khan anas, Thanks for ur reply..!  yes , iam getting values in the system.debug, but unable to display  it in the visualfrocepage! 
 
<b><!--Using the Includetab with multiple controllers--></b>

<apex:page controller="actionfunctiontest1" >
   
   <apex:form >
        <ul>
          <li onclick="passValueToController('Testing'); return false;" style="cursor:pointer;">Click Me</li>
        </ul> 
     
    <apex:actionFunction name="passValueToController" action="{!testing}" reRender="frm" >
        <apex:param name="selectedval" value="selectedval" assignTo="{!selectedval}"></apex:param>
     </apex:actionFunction>
   </apex:form>
       
    <apex:outputPanel id="frm">
           <apex:include pageName="actionfunctiontest2"/>
     </apex:outputPanel>
      
  </apex:page>

<b><!--apexclass--></b>
Apex Controller:

public class actionfunctiontest1 {
 public String selectedval{get;set;}
  // public actionfunctiontest2 t1{get;set;}
  public void testing(){
  system.debug('form the selectedval controller1'+selectedval);
  
      actionfunctiontest2  t1= new actionfunctiontest2();
   } 
}


Includedpage is:

 
<apex:page controller="actionfunctiontest2">
  <apex:form >
 The value passed is:<apex:inputtext value="{!name}"/>
  </apex:form>
</apex:page>


Apex Controller:-

public class actionfunctiontest2 {
   public string name{get;set;}
   public actionfunctiontest2(){
        name =Apexpages.currentPage().getParameters().get('selectedval');
        system.debug('This is the controller2 form 1 im getting the values here');
        system.debug(' sucess:'+ name);
      }
      }

im getting the debug , but unable to render/disply it in the Visualforce page..! 
Thanks in advance...!