0

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.

1

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
}
| improve this answer | |
  • Thanks for reply. I wanted the user to redirect to custom page and this page have the products list ... where user selects the products and add to quote line item – Gidy Nov 4 '15 at 15:42
  • @Gidy - great, simply add that code in what I gave you and you are on your way – Eric Nov 4 '15 at 15:51
  • public PageReference saveAndNew() { save(); PageReference redirectPage = new PageReference('/' + quoteId); redirectPage.setRedirect(true); return redirectPage; return null; } This the code I have added after your say. But it still returning to the quote page. Not to the products list page. – Gidy Nov 4 '15 at 18:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.