+ Start a Discussion
Eager-2-LearnEager-2-Learn 

Reference a Lookup or master field twice on a single page

Hi,

I am trying to create a visual force page that will have two fields Source and Destination but they both reference the same back end master/detail field.  This page uses Opportunity as the standard controller and the child table/object as the extension.  I want the user to be able to select Opp A in the source field and Opp B in the dest field for example.  This seems to work fine.  I cannot seem to get any controller action to occur using the onchange event so I am thinking I could get around this with an additional button named MOVE.

How can I reference both of the different values in these two fields from my controller when they have a VALUE setting that is the same?  Below is some of the main code snippet around the VF page.

<apex:page StandardController="Opportunity" Extensions="Enrollment_MoveLatestEnrollContr2" id="Page" tabstyle="Opportunity"
           sidebar="false" showHeader="false" title="Move Latest Enrollment" >
        
    <apex:sectionHeader title="Move Latest Enrollment" subtitle="Move Latest Enrollment" />     
    <apex:form id="myForm">
        <apex:pageMessages escape="false" />  
        <apex:PageBlock id="pbSrceDest" rendered="{!isAdmin}">                 
            <apex:pageBlockSection columns="1" title="Select a Destination Opportunity"  collapsible="false" >
                <apex:inputField id="SourceOpp" label="Source Opportunity" value="{!Enrollment.Opportunity__c}" />            
                <apex:inputField id="DestOpp" label="Destination Opportunity" value="{!Enrollment.Opportunity__c}" />               
            </apex:pageBlockSection>
...
...

Thanks in advance for your assistance:)

 

Best Answer chosen by Eager-2-Learn
sfdcfoxsfdcfox
You will need to make a second instance of the object. You can't store two values in a single lookup field at once. That would be like trying to write the following code: String myString = new String[] { 'Hello', 'World' }. Obviously, you can't store an array in a normal primitive, and similarly you cannot store two values in a single lookup by referencing it more than once. One value would win over the other (indeterminate), and the other value would be ignored.

                <apex:inputField id="SourceOpp" label="Source Opportunity" value="{!Enrollment.Opportunity__c}" />           
                <apex:inputField id="DestOpp" label="Destination Opportunity" value="{!Enrollment2.Opportunity__c}" />