Skip to main content
I already have VF page which has the Save and cancel button , I want to create a new button " Save & New ".. i do not know how to make it return to the page to create a new record 

public PageReference doFullSave(){

 // this is my Save method

}

public PageReference doFullSave1(){ // this is my save and new method which has to return to the save mode again 

   doFullSave();

  PageReference retPage = new PageReference('/'+ ApexPages.currentPage().getParameters().get('retURL'));

  PageReference returnPage = new PageReference(ApexPages.currentPage().getParameters().get('retURL'));

   return returnPage;

    }

VF page :

<apex:pageBlockButtons >

<apex:commandButton value="Save" action="{!doFullSave}"/>

<apex:commandButton value="Cancel" action="{!doCancel}" immediate="true"/>

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

</apex:pageBlockButtons>

This is the url on the new record page 

sandbox--c.cs4.visual.force.com/apex/CallLog?CF00N6000000268Gm=test12345&CF00N6000000268Gm_lkid=a0wP00000010bHcIAI&retURL=%2Fapex%2FSL_MassEdit_CallLog%3FpId%3Da0wP00000010bHcIAI%26justView%3Dtrue%26page%3D0%26cbf%3Dnull%26cbaf%3Dnull%26qb%3DAll%26qs%3DAll%26qct%3DAll%26qtt%3D%26sortE%3DName%26sortD%3DASC%26cb_letterFilter%3DAll&scontrolCaching=1&sfdc.override=1
4 respostas
  1. 12 de mai. de 2016, 19:17
    Hi Pooja,

    User below code for save and New button :

    public PageReference doFullSave1(){

       doFullSave();

    String str = ApexPages.currentPage().getUrl().subStringAfter('/').substringBefore('?');

       return new PageReference('/apex/' + str).setRedirect(true);

    }         

    Note : This code first save your current record and after that redirect it to the same page after saving changes.

    If this post solves your problem kindly mark it as solution.

    Thanks.
0/9000