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 .

HƯỚNG DẪN THIẾT KẾ WEB CHUẨN SEO

  Hướng dẫn thiết kế web chuẩn seo .  Thế nào là thiết kế web chuẩn seo? Tại sao bạn cần phải biết thiết kế web chuẩn seo. Bởi vì, chuẩn seo là một phần rất quan trọng của một trang thiết kế web. Bạn muốn tìm được khách hàng? Muốn từ khóa bạn nhanh lên TOP thì điều đầu tiên bạn cần làm là trang web của bạn được thiết kế chuẩn seo. Không chỉ chuẩn seo về trang web mà bài viết cũng cần được tối ưu hóa cho chuẩn seo. Có bao nhiêu yếu tố để thiết kế được trang web chuẩn seo?

Sample VS code setting

  When you are a software developer, you need to configure your IDE working with most convinience for your working, bellow is a sample code snippet to config your IDE {   "diffEditor.ignoreTrimWhitespace" : false ,   "javascript.updateImportsOnFileMove.enabled" : "always" ,   "[typescriptreact]" : {       "editor.defaultFormatter" : "esbenp.prettier-vscode"   },   "editor.formatOnPaste" : true ,   "workbench.settings.applyToAllProfiles" : [],   "editor.tabSize" : 2 ,   "redhat.telemetry.enabled" : true ,   "editor.codeActionsOnSave" : {       },   // "editor.codeActionsOnSave": {   //   "source.fixAll": "explicit",   //   "source.fixAll.eslint": "explicit",   //   "source.organizeImports": "explicit",   //   "source.sortMembers": "explicit",   //   "javascript.showUnused": "...