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

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.

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 >
  Build and Dockerize a Full-stack React app with Node.js, MySQL and Nginx React.js is a common and famous front-end web frameworks. Yet, in most situations, a web application will require back-end services to process different transactions. React.js as a front-end framework is not complete without a back-end service to make up a complete full-stack application. On the other hand, Docker is a perfect containerizing technology used to set up all the environments you need set up for a full-stack application. This is because Docker uses an abstract concept built on top of a low-level operating system platform that enables you to execute one or even more containerized activities or services within one or more virtualized instances. Thus, Docker will help you deploy a full-stack React application with the back-end environments such as Node.js and Django. Why Dockerize a React application with Docker A React full-stack application has different services, and it runs as a multi-container ...