I have created a visualforce page that displays both opportunity and contact fields that I want users to be able to edit and save. I am using the opporutnity standard controller and added the following extension so as to be able to override (or add to) the standard save functionality with the 'SaveBoth' method (below). I am having trouble populating the contact object with the correct related record data.
I am recieveing the following error:
"Invalid foreign key relationship: Opportunity.AccountId"
public with sharing class NewLeadControllerExtension
{
ApexPages.StandardController controller;
public Opportunity oppt {get; set;}
public Contact cont {get; set;}
public NewLeadControllerExtension(ApexPages.StandardController controller)
{
this.controller = controller;
oppt = (Opportunity)controller.getRecord();
cont = new Contact();
cont.Id = oppt.Account.Contact.Id;
//cont.AccountId = oppt.AccountId;
}
public PageReference SaveBoth()
{
controller.Save();
update cont;
return null;
}
}
I also tried using the line commented out in the code above instead of the line above it
cont.AccountId = oppt.AccountId
and received an
"MISSING_ARGUMENT, Id not specified in an update call"
Any advice on how to populate the contact Id correctly?
Thanks!
I have researched everything I could find on this subject but still haven't managed to solve it. The code base I started from initially can be found at Visualforce - Display fields from multiple objects