function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sfdc startsfdc start 

plz answer how to create a save and new button in vf page using standarcontroller...........

IN VF page while working on standard object which i want to use the command button  " [save and new] " how ..?
Best Answer chosen by sfdc start
Arpit Jain7Arpit Jain7
Hi you can write below code in your controller class

public PageReference SaveAndNew()
{
    insert acc;// code to do saving goes here
    PageReference pageRef = new PageReference('/001/e'); // Replace it with 3 digit unique code for your object
    return pageRef;
}

Call SaveAndNew method in your VF page

<apex:commandButton action="{!SaveAndNew}" value="Save and New"/>

Please mark this as the best answer if this helps.

All Answers

NagendraNagendra (Salesforce Developers) 
Hi sfdc start,

You can simply use the quick save action for save and new in standard controller.please find the below code for your reference.The below code is for saving a record and will not redirect you to the new record page.Once after clicking on save and new button record gets saved into the database but still you will be in the same page.
<apex:pageBlockButtons> 
<apex:commandButton action="{!save}" value="Save"/>
<apex:commandButton action="{!quicksave}" value="Save and New"/>
 <apex:commandButton action="{!cancel}" value="Cancel"/> 
</apex:pageBlockButtons>
If you want the record to be inserted and redirected to the save and new page then you have to refer a controller extension to the standard controller.

Please use this method in the extension class.
 
public Account acc{get;set;}
public void saveAndNew(){
insert acc;
acc.clear();
}



Kindly mark it as best answer if its resolved.

Best Regards,
Nagendra.P
sfdc startsfdc start
its not working............................
 
Arpit Jain7Arpit Jain7
Hi you can write below code in your controller class

public PageReference SaveAndNew()
{
    insert acc;// code to do saving goes here
    PageReference pageRef = new PageReference('/001/e'); // Replace it with 3 digit unique code for your object
    return pageRef;
}

Call SaveAndNew method in your VF page

<apex:commandButton action="{!SaveAndNew}" value="Save and New"/>

Please mark this as the best answer if this helps.
This was selected as the best answer
Gautam kumar 132Gautam kumar 132
public Account acc{get;set;}
 public void SaveandNew(){
        upsert acc;
        acc=new Account ();
    }
adityasingh bisenadityasingh bisen
use the below code in your extension controller .

public with sharing class extenioncontroller{
public Account acc;

public controllerextension (ApexPages.StandardController controller) {
this.acc=(account__c)controller.getrecord();
}

public PageReference SaveAndNew(){
insert  acc;
PageReference pnext= new PageReference('/apex/vf input page ');
pnext.setredirect(true);
return pnext;
}