I want to save record from 2 visualforce pages both have the some fields. After filling data from one page it should go to second page the save to the obejct. onsert DMl should be only onle one time.
Answer:
First step: you need
to create a apex controller to solve saving data’s object, redirect to next
page when you stay in first page,…
So we create a controller with name is “NextPage”
Controller:
public class NextPage{
public String name{set;get;}
public String
name2{set;get;}
public String
message{set;get;}
public String
phone{set;get;}
public NextPage()
{
name2=
ApexPages.currentPage().getParameters().get('name');
}
public void Submit()
{
Account
acc = new Account();
acc.Name=name2;
acc.Phone=phone;
insert
acc;
message='Data
Saved!!';
}
public PageReference
next_page()
{
PageReference
pageRef = new
PageReference('https://c.ap2.visual.force.com/apex/CommnutyNext?name='+name);
pageRef.setRedirect(true);
return
pageRef;
}
}
Secons step: Creating visualforce page for step one
Page
1:
<apex:page
controller="NextPage">
<apex:form >
<apex:pageBlock >
<apex:pageBlocksection
columns="1">
Name<apex:inputText
value="{!name}"/>
</apex:pageBlocksection>
<apex:commandButton
action="{!next_page}" value="Next"/>
</apex:pageBlock>
</apex:form>
</apex:page>
Secons step: Creating visualforce page for step two
Page 2:
<apex:page
controller="NextPage">
<apex:form >
<apex:pageBlock >
<apex:pageBlocksection
columns="1">
Name <apex:inputText value="{!name2}"/>
Phone <apex:inputText
value="{!Phone}"/>
</apex:pageBlocksection>
<apex:commandButton
action="{!Submit}" value="Submit"/>
<br/>
{!message}
</apex:pageBlock>
</apex:form>
</apex:page>
In the above code basically it is happening that when on VF
page 1 when we enter Name and click Next button , it will redirect us to the VF
page 2. At VF page 2 Name from Page 1 will be shown on the Name input-text and
after entering phone number when we click on Submit button it will create a new
Account hence your aim of one time DML have accomplished.
copy
from topic:
https://developer.salesforce.com/forums/?id=9060G000000BfAxQAK
Comments
Post a Comment