You need to sign in to do that
Don't have an account?
StandardController Extension only saving part of the record after onblur rerender
Hi,
I have a custom payment object that is the basis for a page to save new payments.
I also want to attach multiple sales orders to these payments using a list with checkboxes.
So the process:
1. New payment
2. Choose Account for payment
2.5 The list of sales orders without payments for this account rerenders (onblur event)
3. Enter the amount and Date
4. Check from the list which sales orders apply to this payment
5. Click Save (actually process records at the moment)
All of that works great.
Unfortunately, when I go to save the Payment - only information that was input before the onblur event kicked off is saved.
For instance, usually the user enter's the Description(name) and then the Account. The list of sales orders is refreshed based on the Account. On save, the amount and date don't get saved. If you enter the amount, then the Description and then the Account - the amount is saved.
I have tried every thing I can think of and none of it made a dent. Any help would be greatly appreciated.
note on the code: its got left over stuff in it at the moment commented out from various attempts - i also removed the checkboxsave since the problem happens before that.
<apex:page standardController="PF_Payment__c" extensions="PaymentsExtension"> <p/> <apex:form > <apex:pageBlock title="Payments"> <table> <tr cellpadding="4"> <td>Description:</td> <td> <apex:inputField value="{!PF_Payment__c.name}" required="true"/></td> </tr> <tr> <td>Account: </td> <td><apex:inputField id="ifAccount" value="{!PF_Payment__c.Account__c}"> <apex:actionSupport event="onblur" rerender="salesorderlistblock"/> </apex:inputField></td> </tr> <tr> <td>Amount:</td> <td><apex:inputField id="pAmount" value="{!PF_Payment__c.Amount__c}"/> </td> </tr> <tr> <td>Date Paid:</td> <td><apex:inputField value="{!PF_Payment__c.Date_Paid__c}"/> </td> </tr> <tr> <td>Status:</td> <td><apex:inputField value="{!PF_Payment__c.Status__c}"/> </td> </tr> </table> </apex:pageBlock> </apex:form> <apex:form > <apex:pageblock id="salesorderlistblock"> <apex:pageBlockButtons > <apex:commandButton value="Process Selected" action="{!Save}" rerender="returninfo"/> </apex:pageBlockButtons> <apex:pageBlockTable value="{!Sales_Order}" var="salesorder" cellpadding="4" border="2"> <apex:column headervalue="Sales Order">{!salesorder.so.name}</apex:column> <apex:column headervalue="Record Type">{!salesorder.so.recordtype.name}</apex:column> <apex:column headervalue="Creation Date">{!salesorder.so.createddate}</apex:column> <apex:column headervalue="Description">{!salesorder.so.Description__c}</apex:column> <apex:column headervalue="Price">{!salesorder.so.Price__c}</apex:column> <!-- <apex:column headervalue="Payment">{!salesorder.so.Payment__c}</apex:column> --> <!-- <apex:column headervalue="Payment">{!salesorder.so.Payment__r.name}</apex:column> --> <apex:column headervalue="Add to Payment"> <!-- onclick="!setCurrentStatus('something happened')" --> <apex:inputCheckbox value="{!salesorder.selected}"/> <!--<input id="thecheckbox" type="checkbox" value="{!salesorder.selected}" name="thecheckbox" /> --> <!-- <apex:actionSupport action="{!CurrentStatus}" event="onclick" rerender="returninfo"/> --> </apex:column> </apex:pageBlockTable> </apex:pageBlock> <apex:pageblock id="returninfo"> Current Status: {!CheckBoxDebug} </apex:pageblock> </apex:form> </apex:page>
and the extension
public class PaymentsExtension { public PF_Payment__c pymt; ApexPages.StandardController controller; public PaymentsExtension(ApexPages.StandardController controller) { this.pymt = (PF_Payment__c)controller.getRecord(); this.controller = controller; } private String CurrentStatus = 'Nothing has happened'; public String getCheckBoxDebug() { return CurrentStatus; } public PageReference CurrentStatus() { CurrentStatus = CurrentStatus + ' something '; return null; } List<saleswrapper> salesorderList = new List<saleswrapper>(); List<Sales_Order__c> selectedsalesorders = new List<Sales_Order__c>(); public PageReference Save() { controller.save(); /*upsert this.pymt didn't work*/ /*this.pymt.save(); didnt work*/ PageReference home = new PageReference('/a08/o'); home.setRedirect(true); return home; /* return home; */ } public PageReference getSelected() { selectedsalesorders.clear(); for(saleswrapper sw : salesorderList) if(sw.selected == true) selectedsalesorders.add(sw.so); /* CurrentStatus='something happened'; */ return null; } public List<saleswrapper> getSales_Order() { string queryid = pymt.Account__c; /*= Accountif */ if (queryid != null) { salesorderlist.clear(); for(Sales_Order__c s : [Select id, name, RecordTypeid, RecordType.Name, CreatedBy.Name, CreatedDate, Description__c, Price__c, Payment__c, Payment__r.name from Sales_Order__c where Payment__c = NULL AND Account__c = :queryid]) { salesorderlist.add(new saleswrapper(s)); } } else { for(Sales_Order__c s : [Select id, name, RecordTypeid, RecordType.Name, CreatedBy.Name, CreatedDate, Description__c, Price__c, Payment__c, Payment__r.name from Sales_Order__c where Payment__c = NULL AND Account__c = :System.currentPageReference().getParameters().get('accountid')]) salesorderlist.add(new saleswrapper(s)); /*return salesorderlist; */ } return salesorderlist; } public class saleswrapper { public Sales_Order__c so {get; set;} public Boolean selected {get; set;} public string sonumber {get; set;} public saleswrapper(Sales_Order__c s) { so = s; selected = false; } } }
just use one form for the entire page, i think that may help.
All Answers
just use one form for the entire page, i think that may help.
I'll try that out this weekend. Unfortunately I think I remember having to do have the two forms so the checkbox worked correctly - but maybe not. :)
Thanks for the idea - I'll let you know if it works.
This did indeed fix the problem the problem with the partial save - unfortunately the save to the attached sales order now fails.
I put the part of the code that was working back in to the save but it doesn't appear to process:
public PageReference Save() { controller.save(); /*controller.quicksave(pymt);*/ /*upsert this.pymt*/ /*this.pymt.save();*/ /*Sales_Order__c tempso;*/ selectedsalesorders.clear(); for(saleswrapper sw : salesorderList) { /*System.debug('These are the selected Contacts...');*/ /* CurrentStatus=this.pymt.id; */ CurrentStatus=CurrentStatus + sw.so.name; if(sw.selected == true) { CurrentStatus=CurrentStatus + 'Got in here'; sw.so.Payment__c = this.pymt.id; update sw.so; /*tempso=[SELECT id, payment__c from Sales_Order__c where id = :sw.so.id limit 1]; tempso.payment__c = this.pymt.id; update tempso;*/ selectedsalesorders.add(sw.so); } /* CurrentStatus='something happened'; */ } PageReference home = new PageReference('/a08/o'); home.setRedirect(true); return home; /* return home; */ }
Ok, so I went back to the original upsert and that took care of the new problem.
public PageReference Save() { upsert this.pymt; selectedsalesorders.clear(); for(saleswrapper sw : salesorderList) { if(sw.selected == true) { CurrentStatus=CurrentStatus + 'Got in here'; sw.so.Payment__c = this.pymt.id; update sw.so; selectedsalesorders.add(sw.so); } } PageReference home = new PageReference('/a08/o'); home.setRedirect(true); return home; /* return home; */ }