You need to sign in to do that
Don't have an account?
Ivica Arsenov
How to update existing account with a press of a button in visualforce
Hello guys.I have a problem and dont know how to solve it.What i need to make is to split account creation page in 3-4 visualforce pages.Now i created the first page and linked it with a second page with a button.But now the problem is when i press the "next" button on the first page account is created, and the fields in the second page are not recorded anywhere when i push the "next" button(on the second page). I dont know how to update the account that was created on the first page with the values that i enter in the second page so here is the code:
this is my custom controller:
this is my custom controller:
public class SetupWizard { public Account account {get;private set;} public SetupWizard(){ Id id = ApexPages.currentPage().getParameters().get('id'); account = (id == null) ? new Account() : [SELECT Name, Phone, Industry FROM Account WHERE Id = :id]; } public PageReference save() { try{ upsert account; }catch(exception e){ } PageReference page = new Pagereference('/apex/AddressInformation'); page.setRedirect(true); return page; } }and this is the first visualforce page:
<apex:page sidebar="false" controller="SetupWizard" tabStyle="Account"> <apex:form > <apex:pageBlock title="Account Information" > <apex:pageBlockSection columns="2"> <apex:inputField value="{! Account.name }" /> <apex:inputField value="{! Account.phone}" /> <apex:inputField value="{! Account.industry}" /> </apex:pageBlockSection> <apex:pageBlockButtons location="bottom"> <apex:commandButton value="Next" action="{! save }"/> </apex:pageBlockButtons> </apex:pageBlock> </apex:form> </apex:page>So how to make when press the next button on the second page it updates the account created on the first page with the records that are eneterd on my second page.Any help would be nice thx.
In the first page, you are capturing the name, phone and industry and saving the account.
Now, In the second page, you want to add the some more detail.
In second page, when you click Next, Call a new function and there, try Updating the account once.
Do not use same function for all the Next.
first page -> Next button -> creates a new account -> redirect to second page
second page -> Next Button -> gets that account and updates the account with additional info -> redirect to third page
Have you considered using a Flow (Setup > Create > Workflow & Approvals > Flow) instead of VF Pages and Apex? It allows for multi-screen wizards, and can either gather all of the data before creating the Account as a single trip to the database or return the new Account Id as a variable if you choose to create the Account after screen 1 so that it can be reused to update after additional input.
Thanks,
David
- Create your new Flow (ex. New_Account_Flow)
- Create a VF Page that calls that Flow (see code below)
- Edit the New button for the Account object so that it calls your VF Page instead of the standard page
You can also use the VF Page to pass data to the Flow, such as the logged-in User Id, using apex:param.I'll stop sales-pitching Flow. Just wanted to make sure that you were aware of the options since it seems to be less well known than other parts of the system.