You need to sign in to do that
Don't have an account?
sfdc 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 ..?
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
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. 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.
Kindly mark it as best answer if its resolved.
Best Regards,
Nagendra.P
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.
public void SaveandNew(){
upsert acc;
acc=new Account ();
}
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;
}