You need to sign in to do that
Don't have an account?
Error: Invalid field Contact for SObject Opportunity
Hello,
I am trying to make some edits to the "Simple Quote" application from the appexchange.
I am able to included fields for Opportunities and Accounts, but unable to figure out the syntax for the primary contact associated with the opportunity?
For example:
This works...
{!Opportunity.Account.BillingStreet}
{!Opportunity.QuoteNumber__c}
{!Opportunity.Owner.FirstName}
but this won't work (and produces the error in the subject line of this post):
{!Opportunity.Contact.Name}
I realize an Opportunity can have multiple Contacts, but ideally I would like to include the information for the Decision Maker in the quote.
Anyone help?
There is no Contact directly related to the Opportunity. You will need to query the OpportunityContactRole object with your specific criteria (i.e. Contact Role) and leverage the result returned.
You need to modify your VP page tag to include the extensions parameter, like this:
<apex:page standardController="Opportunity" extensions="quoteEXT" showHeader="false" renderas="pdf">
Then create a simple extension that gets the opportunity, queries the OCR object and populates a value you can use like this:
public class quoteEXT { public final Contact primContact {get; set;} public final Opportunity o {get; set;} public quoteEXT(ApexPages.StandardController controller) { this.o=(Opportunity)controller.getrecord(); try{ ID primContactid = [select id,contactid from opportunitycontactrole where opportunityid=:o.id and isprimary=true LIMIT 1].contactid; primContact = [select id,name from contact where id=:primContactid limit 1]; }catch(QueryException qe){ system.debug('ERROR Querying contact:'+qe.getmessage()); } } }
You can add more field names to your SOQL query if you need more information about the contact. and you could change the where clause if you wanted to use the role instead of the isprimary parameter, just make sure you limit the results to 1 record.
Now, you have the contact available as the name "primcontact" just like you were doing before, so you could add a VF tag like this to your VF page:
</td> <td align="right"><font face="Arial" > <b>Quote for {!Opportunity.Account.Name}</b></font><br/> <b>{!primcontact.Name}</b></font><br/> </td>
Hopefully, that will get you started.
Good Luck!
"create a simple extension"
Am I missing something...I can't find an option or section anywhere to create Extensions
If you look in the documentation
http://www.salesforce.com/us/developer/docs/pages/salesforce_pages_developers_guide.pdf
Chapter 6 (starting on page 58), explains this in detail.
Aha!
Here is the problem...
I don't have the NEW button, even though I am the System Administrator.
Thank you for all the help JimRae, I have contacted Saleforce to help me out with this now :)
You can't create Apex Classes directly in production, that could be your issue.
You need to create them in a development environment (or sandbox) and then deploy them to production along with the appropriate testmethod.
Other than that, the only other thing I can think of would be your profile doesn't have the "Author Apex" option selected.
Hi Guys,
I noticed that an extension was used here to get the Primary Contact of the Opportunity Contact Role. I'm not sure if I read the requirement correctly or not but wouldn't just plain VF do the trick (again sorry if I misread this). Here is the code I used on my VF page just to get the Primary contact.
Hi,
is there a way around to display the contact name when using Professional Edition without the possibility to create an apex class?
thanks for your help