Skip to main content

Save data from two step visualforce page

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

Popular posts from this blog

Docker Compose: Node.js Express and MongoDB example

  Docker   provides lightweight containers to run services in isolation from our infrastructure so we can deliver software quickly. In this tutorial, I will show you how to dockerize Nodejs Express and MongoDB example using   Docker Compose .

MUI dialog make sure user can't click on outside when you're opening dialog

< Dialog       open = { open }       onClose = { ( _event , reason ) => {         if ( reason === "backdropClick" || reason === "escapeKeyDown" ) {           return ;         }         onClose ?.();       } }       maxWidth = { maxWidth }       fullWidth       PaperProps = { {         className : "rounded-lg shadow-lg" ,       } }       disableEscapeKeyDown     > { if (reason === "backdropClick" || reason === "escapeKeyDown") { return; } onClose?.(); }} maxWidth={maxWidth} fullWidth PaperProps={{ className: "rounded-lg shadow-lg", }} disableEscapeKeyDown >

Laravel API Tutorial: How to Build and Test a RESTful API

  Laravel is a PHP framework developed with developer productivity in mind. Written and maintained by Taylor Otwell, the framework is very opinionated and strives to save developer time by favoring convention over configuration. The framework also aims to evolve with the web and has already incorporated several new features and ideas in the web development world—such as job queues, API authentication out of the box, real-time communication, and much more. In this article, we’ll explore the ways you can build—and test—a robust API using Laravel. We’ll be using Laravel 5.4, and all of the code is available for reference on GitHub.