0

I have an object "Details_Page__c" which has a lookup field "Next_Change__c" associated with it. The object is initialized in my controller class -

Details_Page__c detailsPage = new Details_Page__c();

I want to show this field twice in my visualforce page once with the original label and once with a custom label. In VF page -

<apex:pageBlockSection title="Information" columns="2">
     <apex:inputField value="{!detailsPage.Next_Change__c}" />
     <apex:inputField value="{!detailsPage.Next_Change__c}" label="Previous Change" />
</apex:pageBlockSection>

The user is allowed to select different lookup values for these fields from the VF page. However, I want to be able to fetch the values of these fields with separate labels in my controller class and use those separately for different purposes. I know I can fetch the value like -

Next_Change__c nextChange = detailsPage.Next_Change__c;

My question is how do I also read the field with the custom label "Previous Change" ?

Next_Change__c previousChange = ?

1 Answer 1

0

The solution turned out to be pretty simple. Just initialized the same object in the controller with another name along with the existing one.

Details_Page__c detailsPage = new Details_Page__c();    
Details_Page__c detailsPagePrevious = new Details_Page__c();

And referred the same field for this object in the VF page and used that field's value again in the controller

<apex:pageBlockSection title="Information" columns="2">
     <apex:inputField value="{!detailsPage.Next_Change__c}" />
     <apex:inputField value="{!detailsPagePrevious.Next_Change__c}" label="Previous Change" />
</apex:pageBlockSection>

And finally in my controller, used it for my case like -

Next_Change__c nextChange = detailsPage.Next_Change__c;
Next_Change__c previousChange = detailsPagePrevious.Next_Change__c;

You must log in to answer this question.

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