Can any one help me out.Any help is very much appreciated.

I have a custom object name as "RFC__c" and it has a lookup relationship with opportunity object.Now i would like to get the opportunity fields in RFC__c object in a VF page.How to call them.I do get an Error as :

Error: Invalid field Opportunity for SObject RFQ__c

Here is my VF Page :RFQ:

<apex:page Standardcontroller="RFQ__c" sidebar="false" showHeader="false" > 
 <apex:form id="RF"> 
 <h1> <apex:sectionHeader title=" SALES REQUEST FOR QUOTE FORM(RFQ)"  /> </h1> 
 <apex:pageblock >  
  <apex:pageBlockSection title="General Information">  
  <apex:inputField value="{!RFQ__c.Name}" label="Customer Name"/>  
  <apex:inputField value="{!RFQ__c.AccountType__c}"/>
 <apex:inputField value="{!RFQ__c.Date__c}"/>
 <apex:inputField value="{!RFQ__c.Response_Needed_By_Date__c}"/>
 <apex:inputField value="{!RFQ__c.Expected_Order_Date__c}"/>
 <apex:inputField value="{!RFQ__c.ProbabilityOf_Order_With_Requested_Price__c}"/>
<apex:inputField value="{!RFQ__c.Comments__c}"/>
  <apex:pageBlockSection title="Price Request Details">  
  <apex:inputField value="{!RFQ__c.Opportunity.AccSegment__c}"/>  
  • 1). Is the custom object name RFC__c or RFQ__c? 2). can you please check the WSDL for the correct relationship name?
    – highfive
    Sep 30, 2014 at 10:26
  • @highfive:Custom object is : RFQ__c.
    – nikkey
    Sep 30, 2014 at 10:30
  • Go to Setup > Develop > API > Generate WSDL In the generated WSDL check the lookup relationship name for Opportunity from RFQ__c
    – highfive
    Sep 30, 2014 at 10:37

4 Answers 4

apex:inputField value="{!RFQ__c.Opportunity.AccSegment__r}"/>

You need to refer the above like this

<apex:inputField value="{!RFQ__c.Opportunity__r.AccSegment__c}"/>
  • @highfive,@Kiran Mutturu @ Vineeth :Thanks for your reply.It worked when i used the look up field appending with r . <apex:inputField value="{!RFQ__c.RFQOpportunity__r.AccSegment__c}"/>
    – nikkey
    Sep 30, 2014 at 12:07

In order to call parent fields from child object we need to use __r to call parent fields

for example ``

<apex:page standardController="RFQ__c">

 <apex:form >

  <apex:inputField value="{!RFQ__c.Opportunity__r.Contract_Start_Date__c}"/>



Hope This helps you ..


<apex:page standardController="CustomObj__c" recordSetVar="objs">
    <apex:pageBlock title="">
         <apex:pageBlockTable value="{! objs}" var="item" >
            <apex:column headerValue="Opp. Name">
                <apex:outputText value="{! item.opp_to_exp__r.Name}"/>

refer the field names with __r.fieldname of the lookup object from the source object

  • :Thanks for your reply : i tried in referring in different ways but i still get an Error :apex:inputField value="{!RFQ__c.Opportunity.AccSegment__r}"/> Error: Invalid field Opportunity for SObject RFQ__c <apex:inputField value="{!RFQ__c.Opportunity__r.AccSegment__c}"/> Error: Invalid field Opportunity__r for SObject RFQ__c <apex:inputField value="{!RFQ__c.Opportunity.AccSegment__r.AccSegment__c}"/>
    – nikkey
    Sep 30, 2014 at 10:24
  • As I told you replace this line <apex:inputField value="{!RFQ__c.Opportunity.AccSegment__c}"/> with <apex:inputField value="{!RFQ__c.Opportunity__r.AccSegment__c}"/> Sep 30, 2014 at 11:03

When you are accessing fields of a look up object you need to make sure you are using the correct relationship name. You can't assume the relationship name and access it like obj.My_Lookup__c.LookupField__c.

If you are not sure about the relationship name, best way is to generating the WSDL and check the relationship name. You can generate the WSDL at Setup > Develop > API > Generate WSDL

After generating, find for the line <complexType name="RFQ__c"> and in the below lines you can find the correct relationship name. Use that in the Visualforce pag.

<apex:inputField value="{!RFQ__c.Correct_RelationshipName__r.AccSegment__c}"/>

You must log in to answer this question.

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