I have a visual force page that is invoked on a custom button on opportunity detail page. I wanted to include another page to display some custom data to this visual force page . How do I pass a custom variable on opportunity to the controller of the page included? I wanted to display results on the included page when the main page is rendered.

main page:

<apex:page standardController="opportunity" extensions="CMEditController">
<apex:form >
<apex:outputPanel id="errorMessagespanel" >
<apex:pageMessages ></apex:pageMessages> </apex:outputPanel>

<apex:pageBlockSection title="Call Outcome Details" columns="2">
<apex:inputField value="{!opportunity.LeadSource}"/> 

<apex:pageBlockButtons location="Bottom">
<apex:commandButton action="{!saveandclose}" value="Save"  rerender="errorMessagespanel"/>
<apex:commandButton action="{!cancel}" value="Cancel" onclick="window.top.close()"/>
<apex:pageBlock >

<apex:include pageName="displayNotes"/>


included page :

<apex:page Controller="NotesController" tabStyle="note">

    <apex:dataTable value="{!notesList}" var="note" cellspacing="5">
   <apex:column >
     <apex:facet name="header">Note</apex:facet>
     <DIV style= "width:100%;overflow:hidden;word-wrap:break-word">

   <apex:outputText value="{!note.noteText}"/>   
</DIV>   </apex:column>   


Notes Controller needs a custom field data from opportunity to query Notes to be displayed.

3 Answers 3


<apex:include> seems to be pretty limited in terms of what it supports. I assume the two pages get built together in the same context, so one method of transferring data would be to use some static variables in one of the controllers or a third class. You could set the variables in the primary controller and read them in the other, though you'd probably need to do it in the constructor and you could still potentially get caught out by the order of execution.

If you want to step it up a little, there are also ways to hook up two controllers so that they can call methods on each other via the use of a common base class, you can find more information on that on developer.salesforce.com.


You might want to take a look at Visualforce Custom Components, these seem to be a good fit for your use case here, since you can define attributes to pass into them from your custom controller. Here is a demonstration i put together for you.

First the Apex code...

public class NoteInfo
    public String noteText {get;set;}

public with sharing class MyCustomController {

    public List<NoteInfo> noteList {get;set;}

    public MyCustomController() {
        NoteInfo note1 = new NoteInfo();
        note1.noteText = 'Note 1';
        NoteInfo note2 = new NoteInfo();
        note2.noteText = 'Note 2';
        NoteInfo note3 = new NoteInfo();
        note3.noteText = 'Note 3';      
        noteList = new List<NoteInfo> { note1, note2, note3 };

Next the custom component i called NotesList...

    <apex:attribute name="notesList" type="NoteInfo[]" description="Lists notes"/>
    <apex:dataTable value="{!notesList}" var="note" cellspacing="5">
        <apex:column >
            <apex:facet name="header">Note</apex:facet>
                <div style= "width:100%;overflow:hidden;word-wrap:break-word">
                    <apex:outputText value="{!note.noteText}"/>   

Finally the Visualforce page using the component...

<apex:page controller="MyCustomController" showHeader="true" sidebar="true">

    <!-- Other Visualforce code for the record / information being displayed -->

    <c:NotesList notesList="{!noteList}"/>


This resulted in my page showing the following...

enter image description here


Another approach would be using an <apex:iFrame> instead of <apex:include> in which you can append the parameter in the src attribute for example :-

 <apex:iframe height="500px"  width="700px" src="/apex/GardenShedQuote_PDF?yourCustomVariableName={!yourCustomVariableName}"/>

and in the controller of the embedded page, fetch the parameter with ApexPages.CurrentPage().getParameters().get('yourCustomVariableName').That way your variable would be appended in the url of the included page and you can easily fetch it in the controller. Hope it works for you!!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .