[SalesForce] Need Save and New method in controller for save and new custom button

I trying to add Save and new button at quote line item page editor level. But I'm stuck with ideas.

Controller:

    public PageReference save() {
        checkRecursive.run = false;

        refresh();
        for (QuoteLineItemWrapper quoteWrap: TotalquoteLineItems) {
            if (quoteWrap.quoteLineItem.DisCount_Amount__c > 0) {
                if (quoteWrap.subTotal != 0) {
                    Double variableONE = 100 - (((quoteWrap.subTotal - quoteWrap.quoteLineItem.DisCount_Amount__c) * 100) / quoteWrap.subTotal);
                    quoteWrap.quoteLineItem.Discount = variableONE;
                }
            }
        }
        List < QuoteLineItem > itemsToInsertOrUpdate = new List < QuoteLineItem > ();
        List < QuoteLineItem > ExiistingitemsToUpdate = new List < QuoteLineItem > ();

        for (QuoteLineItemWrapper itemWrapper: quoteLineItems) {
            itemsToInsertOrUpdate.add(itemWrapper.quoteLineItem);
        }
         for (QuoteLineItemWrapper itemWrapper: ExistingquoteLineItems) {
            ExiistingitemsToUpdate.add(itemWrapper.quoteLineItem);
        }


        String errorMsg;

        if (!itemsToInsertOrUpdate.isEmpty()) {

                            return null;
            }


            if (mode == 'Add' || mode == 'AMS')
                try {
                    insert itemsToInsertOrUpdate;
                    if(ExiistingitemsToUpdate!=null && ExiistingitemsToUpdate.size()>0){
                       update ExiistingitemsToUpdate;
                    }
                    MRsort();

                } catch (Exception e) {
                errorMsg = e.getMessage();               
            } else if (mode == 'Edit') {
                try {
                    update itemsToInsertOrUpdate;
                } catch (Exception e) {
                    errorMsg = e.getMessage();
                }
            }
            if (mode != 'Edit') {
                errorMsg = updateTAC(errorMsg);
                //return null;
            }
        }
 if (errorMsg != null && errorMsg != '') {
            ErrorManager(errorMsg);
            //Apexpages.Message errMsg = new Apexpages.Message(Apexpages.Severity.ERROR , errorMsg);
            //Apexpages.addMessage(errMsg);
            return null;
        }
        return new PageReference('/' + quoteId);
    } 

VF ppage:

<body onload="OnLoadQuantityModif();">           
<apex:form id="pageform" >

<apex:pageMessages escape="false" ></apex:pageMessages>
<apex:actionFunction name="sayHello" action="{!save}" rerender="out" status="myStatus"/>
 <apex:pageBlock id="pb" title="New Quote Line Items for {!quote.Name}">
 <font color="red"><apex:outputText value="{!strLeadMsg}"  /></font>
<!--            Add/Edit Products to this quote from {!priceBook.Name}-->
          <br/> 
            <br/>  
            <apex:pageblockbuttons >
                <apex:commandButton value="Save" action="{!save}" rendered="{!IF(ISNULL( strAfficherSaveButton) ,false,true)}"/>
                <apex:commandButton value="Save Multiple items" action="{!saveMultyplesitems}" rendered="{!IF(ISNULL(strAfficherMultipleButton) ,false,true)}"/>
                <apex:commandButton value="Cancel" action="{!cancel}"/><br/> <br/>


                <apex:commandButton action="{!Save}" value="Save & New" id="saveAndNew"/>
                    <apex:param name="newAndSave" value="newAndSave" />

Here I did not copied the whole save method. I'm not sure that I have to write a new method for save and new or I can just add some code in save method.

Thanks in advance.

Best Answer

If you add a save method to your controller it will be used instead of the standard save method provided by the standard controller.

So whatever you want to happen when the user clicks save you will have to write.

After rereading I get what you are asking now:

You can add another method to use the current save() method then after that is finished executing have it do the additional code needed for the new part

public pagereference saveandnew(){
   save();
   //Do what you need to do to direct the user to the NEW record
   //not sure if it is the standard page you want to take them to or something in your current page
}