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

Updating two sObject types in one visualforce page

I am trying to create a VF page that allows me to update an Opportunity and Account record at the same time (or maybe in two steps, either way I don't care).  I have heard that creating a custom button would work and I have played with a class, but can't get anything to function properly.  How would it be possible to do this?


You should be able to update as many records as you like, as long as you are using extension or custom controllers.   How are you accessing the data?  i.e. are you pulling back the opportunity details and looking to get at the parent account?


I wrote a blog post some time ago around this - its based on updating a parent and its children but should give you some pointers:


Exactly, I am working with the Opp and pulling the parent account.  Your blog post is fantastic and should help me get exactly what i need; thanks for sharing!!!


I am actually still having some issues with this.  I don't fully understand how to port the extension you created over to be used for Account/Opps.  


Just to give a quick rundown on what I am doing, I am creating a wizard to close out an Opportunity.  We have fields under the Account that need to be populated on Opp Close.  Therefore, all I need to do is create a visualforce page that allows you to edit fields from both the Account and Opp all on one page and save the Account first and the Opp second (to prevent validation issues).  


Any help is much appreciated.  


So is your wizard using the Opportunity standard controller?  If so, you'll need to pull back the associated account in your extension controller (I'd do it in the constructor myself) and then use that record to back the input fields on the final page.  Then you'd override the save method to first save back the account and then the opportunity.