function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
soltrainsoltrain 

Visualforce problem with Contacts and Opportunities

Hi all - 

 

   I am attempting to edit a visualforce page from the "Simple Quotes" application from appexchange. My question is much like one that was asked previously here: http://boards.developerforce.com/t5/General-Development/Error-Invalid-field-Contact-for-SObject-Opportunity/td-p/160764

 

I'm attempting to use the Opportunity object to store information about orders. The object already includes a lookup for Account, but it did not include a lookup for a Contact, the person who would have placed the order. 

 

I added a lookup field for Contact in the Opportunity object and want to reference it in a visual force page that generates a printable quote. Here is the code:

 

Account Information

Account name: {!Opportunity.Account.Name}  ---> Works as expected

 

Customer Information

Customer Name: {!Opportunity.Contact__c}   ---> This displays what looks to be an internal database ID instead of a name

Customer Name: {!Opportunity.Contact.Name}  ----> This returns the error: Error: Invalid field Contact for SObject Opportunity

 

I don't understand why Opportunity.Contact.Name does not work as expected. It seems both the Account and Contact are both lookup relationships to Opportunity. The advice in the other thread was to query the OpportunityContactRole object, but I've never heard of this object - is it hidden from the list of objects viewable from the web interface? I've added a custom lookup field to Contact, if I query this OpportunityContactRole, will it return the same result as what the user selects in the lookup field?

 

Thanks for your help!

Best Answer chosen by Admin (Salesforce Developers) 
pankaj.raijadepankaj.raijade

You should try {!Opportunity.Contact__r.Name} instaid of {!Opportunity.Contact.Name}.

 

Regards,

Pankaj Raijade

All Answers

pankaj.raijadepankaj.raijade

You should try {!Opportunity.Contact__r.Name} instaid of {!Opportunity.Contact.Name}.

 

Regards,

Pankaj Raijade

This was selected as the best answer
soltrainsoltrain

It worked! You are a genius! Why does it work this way? Could you point me to some documentation that would help me understand?

pankaj.raijadepankaj.raijade

the contact field you were trying to use is standard field so relationship is also standard.

when you are using custom field then only we need to add __r.

 

Regards,

Pankaj Raijade.

 

Please check out this application on appexchange, "Object Converter

 

Using Object Converter you can convert any standard or custom object to one or more standard or custom objects with a single click of button or link