You need to sign in to do that
Don't have an account?
Saranya M
Input field to display lookup field in Visualforce page
I have created the below Visualforce page which gets the data for the Opportunity object from the user. The Opportunity object has a field - Account name which contains a lookup to the Account object. But when I refer it through the Inputfield using {!opportunity.account.name}, it is displayed as a text box and not as a lookup field to Account object. Can someone please tell me how to modify the code?
<apex:page controller="opptycontroller" tabStyle="Opportunity">
<apex:sectionHeader title="New Customer Opportunity" subtitle="Step 2 of 3"/>
<apex:form >
<apex:pageBlock title="Opportunity information" mode="edit">
<apex:pageBlockButtons >
<apex:commandButton action="{!step3}" value="Next"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Opportunity products">
<apex:inputField id="opportunityType" value="{!opportunity.type}"/>
<apex:inputField id="opportunityLeadSource" value="{!opportunity.LeadSource}"/>
<apex:inputField id="opportunityProbability" value="{!opportunity.Probability}"/>
<apex:inputField id="opportunityAccountName" value="{!opportunity.account.name}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
<apex:page controller="opptycontroller" tabStyle="Opportunity">
<apex:sectionHeader title="New Customer Opportunity" subtitle="Step 2 of 3"/>
<apex:form >
<apex:pageBlock title="Opportunity information" mode="edit">
<apex:pageBlockButtons >
<apex:commandButton action="{!step3}" value="Next"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Opportunity products">
<apex:inputField id="opportunityType" value="{!opportunity.type}"/>
<apex:inputField id="opportunityLeadSource" value="{!opportunity.LeadSource}"/>
<apex:inputField id="opportunityProbability" value="{!opportunity.Probability}"/>
<apex:inputField id="opportunityAccountName" value="{!opportunity.account.name}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Every LookUp field store Id of the related object's record and its string type.
Thatswhy we use "accountid".
So,use this <apex:inputfield value="{!opportunity.accountid}"/>.
If we want to access any lookup field in visualforce page,use id with field as mentioned above.
If you satisfy with this suggestion,please mark it as best answer
All Answers
Every LookUp field store Id of the related object's record and its string type.
Thatswhy we use "accountid".
So,use this <apex:inputfield value="{!opportunity.accountid}"/>.
If we want to access any lookup field in visualforce page,use id with field as mentioned above.
If you satisfy with this suggestion,please mark it as best answer
If this resolve your issue. please mark answer as a solution.
I am trying to do the same,
My lookup field name is Congressional_District__c.
<apex:inputField required="true" id="CongressionalRepresentative" value="{!application.Congressional_District__c}" />
application is the object in my controller
I have a Account lookup field with the API name Congressional_District__c.
<apex:inputField required="true" id="CongressionalRepresentative" value="{!application.Congressional_District__c}" />
where application is the object in my controller
How can I achieve this?