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 have managed to be able to query the correct contact and populate the contact ID, but upon 'Save' none of the contact fields on the Visualforce page are updating.
public with sharing class NewLeadControllerExtension
{
ApexPages.StandardController controller;
public Opportunity oppt {get; set;}
public Account acct {get; set;}
public Contact cont {get; set;}
public NewLeadControllerExtension(ApexPages.StandardController controller)
{
this.controller = controller;
oppt = (Opportunity)controller.getRecord();
acct = new Account();
cont = new Contact();
acct.Name = oppt.Account.Name;
cont.Id = [SELECT Id FROM Contact WHERE Name =: acct.Name LIMIT 1].Id;
}
public String getTitle()
{
return 'The Contact ID is '+ cont.Id;
}
public PageReference SaveBoth()
{
update cont;
controller.Save();
return null;
}
}
Sagar - thanks very much for your help but that change makes no difference. There is no error message, the opportunity fields can be changed and saved, but the contact fields are not