function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sdavidow9sdavidow9 

Controller Save function not working

Okay, so in another post I've stated that my log files and debug window aren't working.  I can't figure out why I can't get my save call to acutally update my custom object.  My page has Orders__c and Order_line_items__c.   All I'm trying to do for now is SAVE orders__c (I'm sure once I get that to work, I'll ask about saving the child records...but first thing's first).  I've tried all sorts of stuff and finally resorted to creating a simple page that has none of the child stuff on it and it is updating properly.  I created it in the same fashion 

 

So I created a very simple VF page and controller (extension) that would focus on 1 object, and really 1 field.  It works just fine.  As a matter of fact, if I take that simple VF page and use the controller extension from the larger VF page, it works just fine...so that leads me to believe that my controller extension is just fine and the problem lies somewhere in the page...anyone care to take a look?  I have a boat load of style and .js I'm referencing (which I've pulled out below).  That isn't effecting it either as I've tried leaving it out and still no dice.

Thanks in advance for any help...I'm all sorts of confused.

 

 Pardon the comments and mess:

 

<apex:page standardcontroller="Orders__c" extensions="ppOrderProduct_ctrl" showheader="false" sidebar="false" id="thePage"> <apex:form id="theForm"> <apex:pageBlock title="Beer Order for Distributor {!$User.FirstName}" id="theHeaderPageBlock"> <table class="tblHeader"> <tr> <td class="classHeadCol"><b>Distributor:</b></td><td class="classDataCol">{!shipto.parent.name}</td> <td class="classHeadCol"> <b>Requested Date:</b></td><td class="classDataCol"> <apex:inputField id="RequestedDate" value="{!order.Requested_Delivery_Date__c}" onchange="validateLeadTime();" /> <!-- Make below hidden...made input for troubleshooting Next Pull Date: --> <apex:inputhidden value="{!nextPull.Scheduled_Pull_Date__c}" id="nextPullDate"/> </td> </tr> <tr> <td class="classHeadCol"><b>Ship to: </b></td> <td class="classDataCol"> <apex:outputtext value="{!shipto.name}"/> <!--Ship to is read only on this view... <select> <option value={!shipto.name}>{!shipto.name}</option> </select> --> </td> <td class="classHeadCol"><b>Delivery Type:</b></td><td class="classDataCol"> <apex:outputtext id="delivery_type" value="{!order.container__r.name}" /> </td> </tr> <tr> <td class="classHeadCol"><b>PO Number: </b></td><td class="classDataCol"> <apex:outputtext id="PONumber" value="{!order.P_O_Number__c}"/></td> <td class="classHeadCol"><b>Pic/Del - Location: </b></td> <!-- Below will need to be if statement based on pickup or delivery --> <td class="classDataCol"><apex:inputField id="Location" value="{!shipto.shippingstreet}"/></td> </tr> <tr> <td class="classHeadCol"></td><td></td> <td class="classHeadCol"><b>Equipment Type:</b></td><td class="classDataCol"> <apex:outputtext id="Container" value="{!order.container__r.name}" /> <apex:inputhidden id="containerPalletCap" value="{!order.container__r.Pallet_Capacity__c}"/> </td> </tr> </table> </apex:pageBlock> <apex:pageBlock title="Product List for Order" id="theBlock"> <apex:outputPanel id="thePanel"> <div id="ProductTable"> <apex:inputHidden value="{!order_Line_Items.size}" id="numberofLines"/> <apex:dataTable value="{!order_line_items}" var="oli" id="theTable" rowClasses="odd,even" columnClasses="classSKU, classDESC,classOrderUnit,classOrderQty,classUnitPrice,classPallets,classTotalPrice" styleClass="tableClass"> <!-- <apex:facet name="caption">table caption</apex:facet> --> <!-- <apex:facet name="header">table header</apex:facet> --> <apex:facet name="footer"> <apex:inputField id="Container" value="{!order.container__r.name}" /> Equipment: {!order.container__r.name} ({!order.container__r.Pallet_Capacity__c} Pallets) <br/> Capacity: <input size="3" disabled="true" value="" id="TotalPallets1" Class="palletfieldClass"/> (<input size="3" value="" disabled="true" id="percentFull" Class="palletPercentfieldClass"/>) <input size="3" value="" disabled="true" id="PalletsUntilFull" Class="palletfieldClass"/> until full </apex:facet> <apex:column > <apex:facet name="header">{!$Label.omsSKU}</apex:facet> <apex:facet name="footer">Total</apex:facet> <apex:outputText value="{!oli.ship_to_product__r.SKU_Number__c}"/> <!-- Make below hidden...using for troubleshooting --> <apex:inputhidden value="{!oli.ship_to_product__r.Lead_Time__c}" id="leadTime"/> </apex:column> <apex:column > <apex:facet name="header">{!$Label.omsDescription}</apex:facet> <apex:facet name="footer"></apex:facet> <apex:outputText value="{!oli.Product__r.Description}"/> <p class="specialMessage"><apex:outputText value="{!oli.product__r.Special_Message__c}"/></p> </apex:column> <apex:column > <apex:facet name="header">{!$Label.omsOrderUnit}</apex:facet> <apex:facet name="footer"></apex:facet> <apex:outputText value="{!oli.ship_to_product__r.Order_Unit__c}"/> </apex:column> <apex:column id="oq"> <apex:facet name="header">{!$Label.omsOrderQuantity}</apex:facet> <apex:facet name="footer"></apex:facet> <apex:inputField styleClass="oqInputField" value="{!oli.Quantity__c}" onchange="updatePrice(getLineIndex('{!$Component.linequantity}'),1);" id="linequantity"/> <!-- orig below <apex:inputField styleClass="oqInputField" value="{!oli.Quantity__c}" onchange="updatePrice('{!$Component.linequantity}','{!$Component.ePricefield}','{!$Component.kcPrice}', '{!$Component.base_unit_pallet__c}','{!$Component.uompPallet}','{!$Component.totalBaseUnits}', '{!$Component.totalLinePallets}');" id="linequantity"/> --> </apex:column> <apex:column > <apex:facet name="header">{!$Label.omsKegCasePrice}</apex:facet> <apex:facet name="footer"></apex:facet> <!-- <apex:outputText value="{!oli.Price__c}" id="kcPrice"/> --> <!-- <apex:inputField styleClass="oqInputField" value="{!oli.Price__c}" id="kcPrice"/>--> <apex:inputText styleClass="ReadOnlyFieldClass" disabled="true" value="{!oli.Price__c}" id="kcPrice"/> </apex:column> <apex:column > <apex:facet name="header">{!$Label.omsKegCasePallet}</apex:facet> <apex:facet name="footer"></apex:facet> <apex:inputtext styleClass="ReadOnlyFieldClass" disabled="true" id="uompPallet" value="{!oli.ship_to_product__r.Base_Unit_Order_Unit__c}"/> </apex:column> <apex:column > <apex:facet name="header">{!$Label.omsPallets}</apex:facet> <apex:facet name="footer"><input size="3" value="" disabled="true" id="TotalPallets" Class="ReadOnlyPriceFieldClass"/></apex:facet> <apex:inputtext styleClass="ReadOnlyPriceFieldClass" disabled="true" size="3" value="{!calculatedValue}" id="totalLinePallets" /> </apex:column> <apex:column > <apex:facet name="header">{!$Label.omsPrice}</apex:facet> <apex:facet name="footer"><apex:inputtext styleClass="ReadOnlyPriceFieldClass" disabled="true" value="{!order.Amount__c}" id="OrderTotalPrice"/></apex:facet> <!-- <apex:outputText value="{!oli.Extended_Price__c}" id="ePrice"/> styleClass="epfieldClass"--> <!--<apex:inputField value="{!oli.Extended_Price_OMS__c}" id="ePricefield" styleClass="epfieldClass" onchange="epricechange('{!$Component.linequantity}','{!$Component.ePricefield}','{!$Component.kcPrice}');"/> --> <apex:inputText disabled="true" value="{!oli.Extended_Price__c}" id="ePricefield" styleClass="ReadOnlyPriceFieldClass"/> <!-- Base Unit/Pallet --> <apex:inputhidden value="{!oli.ship_to_product__r.Base_Unit_Pallet__c}" id="base_unit_pallet__c" /> <!-- Total Base Units (calculated) --> <apex:inputhidden value="{!totalBaseUnits}" id="totalBaseUnits" /> </apex:column> <!-- Remove below, for troubleshooting calculations <apex:column > <apex:facet name="header">Base Unit/Pallet</apex:facet> <apex:facet name="footer"></apex:facet> </apex:column> <apex:column > <apex:facet name="header">Total Base Units (calculated)</apex:facet> <apex:facet name="footer"></apex:facet> </apex:column> --> </apex:dataTable> </div> </apex:outputPanel> <apex:commandButton value="Save" action="{!mysave}"/> <!-- <apex:pageBlockButtons location="bottom"> </apex:pageBlockButtons> --> </apex:pageBlock> </apex:form> </apex:page>

 Controller:

public with sharing class ppOrderProduct_ctrl { Account distributor; Account shipto; Orders__c order {get; set;} List<Order_Line_Item__c> oli; string size; public String getSize() { return size; } public void setSize (String s) { size = s; } public string totalBaseUnits {get; set;} public string calculatedValue {get; set;} public date calcDate;// {set;} pull_order_schedule__c nextPull; /* Using calculatedValue for place holder when needing a calculated input box */ public date getCalcDate() { //order.Requested_Delivery_Date__c+10; //validateDate(); return calcDate; } public void setCalcDate() { //this.calcDate=calcDate; } public ppOrderProduct_ctrl(ApexPages.StandardController stdController) { system.debug('###ctrl message...'); order = [select id, orders__c.P_O_Number__c, container__r.name,container__r.pallet_capacity__c, orders__c.amount__c, requested_delivery_date__c, distributor__c, supplier__c from Orders__c where id =:ApexPages.currentPage().getParameters().get('id')]; shipto=[select a.name,a.shippingcity, a.shippingstreet, a.shippingstate, a.parent.name from account a where id = :order.Distributor__c]; //distributor=[select name from account where id = :ApexPages.currentPage().getParameters().get('id')]; nextPull=[select np.Scheduled_Pull_Date__c from pull_order_schedule__c np where np.supplier__c=:order.Supplier__c and np.status__c='Active' ORDER BY np.scheduled_pull_date__c ASC limit 1 ]; } public Account getShipto() { if(shipto == null) distributor = new Account(); return shipto; } public Orders__c getOrder() { //if(order == null) order = new Orders__c(); return order; } public pull_order_schedule__c getnextPull() { if(nextPull == null) nextPull = new pull_order_schedule__c(); return nextPull; } public List<Order_line_Item__c> getOrder_Line_Items(){ oli=[select ol.Product__r.Description,ol.product__r.special_message__c, ol.quantity__c, ol.extended_price_OMS__c, ol.id, ol.price__c, ol.ship_to_product__r.sku_number__c, ol.ship_to_product__r.base_unit_order_unit__c, ol.ship_to_product__r.order_unit__c, ol.ship_to_product__r.base_unit_pallet__c, ol.extended_price__c, ol.ship_to_product__r.lead_time__c from Order_Line_Item__c ol where Order__c=:ApexPages.currentPage().getParameters().get('id')]; return oli; } public PageReference mysave() { system.debug('###Save method invoked...'); update order; return null; } }

 

Best Answer chosen by Admin (Salesforce Developers) 
sdavidow9sdavidow9

I think I solved my problem.  There were 3 main issues:

1)  I had apex:inputtext disabled=TRUE.  Apparently that doesn't fly.  

2)  I had apex:inputhidden value="{!order_line_items.size}" as the number of lines from my data table.  This apparently was trying to bind a query size to an sobject (or something like that).  I made this an input type="hidden" (and then referenced it as the id rather than thepage:theform:thepageblock:id...)

3) I believe the java string error dealt with another apex:inputhidden on a date field.  Since I was referencing this for client side validation, I made it an input type=hidden and it was no longer trying to bind it on upate.  Looks like things are working...

 

Well, as good as can be expected with me coding it :smileywink:

All Answers

NaishadhNaishadh

Hi,

 

what error you are getting? I tried to do it using some sample object and it is working fine. Here is the code for your reference.

 

 

<apex:page standardController="ParentObject__c" extensions="formum16398Con"> <apex:form> <apex:pageblock> <apex:pageblockSection> <apex:pageBlockSectionItem> <apex:outputtext>name</apex:outputtext> <apex:inputtext value="{!data.name}"/> </apex:pageBlockSectionItem> <apex:pageblockSectionItem> <apex:outputtext>pet name</apex:outputtext> <apex:inputtext value="{!data.Pet_Name__c}"/> </apex:pageblockSectionItem> <apex:pageblockSectionItem> <apex:commandButton value="Save" action="{!save}"/> </apex:pageblockSectionItem> </apex:pageblockSection> </apex:pageblock> </apex:form> </apex:page>

 

 

public with sharing class formum16398Con { private ParentObject__c pObj; public formum16398Con(ApexPages.StandardController controller) { pObj = [select name,Pet_Name__c from ParentObject__c limit 1]; } public ParentObject__c getData() { return pObj; } public PageReference save() { update pObj; return null; } }

 

 

 

 

 

 

sdavidow9sdavidow9

I was able to get my debug log (not system log window) working by creating a new user and logging in with that...so I don't know what the deal is. I will try my old login again today...

 

I was getting the error in my debug logs:

apex:input text element value must resolve to a String type!

 

Some research revealed it had to do with setting an to disabled=true. I made all of them disabled=false and this error is gone...Sort of messes with the GUI I'd hoped for, but smaller issue.

 

Now I'm getting there error:

java.lang.String cannot be cast to java.util.Date

When I save (or try to). I found 2 postings related to this.

Which seem to deal with this error: http://community.salesforce.com/sforce/board/message?board.id=Visualforce&thread.id=8709 and http://community.salesforce.com/sforce/board/message?board.id=Visualforce&thread.id=12756 The first has a pretty big work around, the other has to do with trapping for NULL values on dates...I'll update after I try these.

sdavidow9sdavidow9

I'm also getting this in a debug log:

Element thePage called method {!checkManageability} returned type PageReference: none

 Man, I'm all turned around since I was able to get rid of the java string error by removing a apex:hidden date field, but now my save routine isn't even being called.  Time to step back and...get some coffee?

sdavidow9sdavidow9

Okay, looks like my save issue comes down to this line:

 

<apex:inputHidden value="{!order_Line_Items.size}" id="numberofLines"/>

 

 After pulling out most of the code, and then commenting out piece by piece...this looks to be part of the problem.

I'm using this input to store the number of lines in my data table in order to iterate through with javascript to format and do calculations that are not stored in SFDC.  

 

I'm doing it with js vs. a controller and rerender for user experience.  As the user updates the table, I need to do data validation - make sure to update the "total cost" on the fly and be sure they don't hit certain limits.

 

Any idea how I can get the number of rows of a data table without this...or rather antoher way?

 

sdavidow9sdavidow9

I think I solved my problem.  There were 3 main issues:

1)  I had apex:inputtext disabled=TRUE.  Apparently that doesn't fly.  

2)  I had apex:inputhidden value="{!order_line_items.size}" as the number of lines from my data table.  This apparently was trying to bind a query size to an sobject (or something like that).  I made this an input type="hidden" (and then referenced it as the id rather than thepage:theform:thepageblock:id...)

3) I believe the java string error dealt with another apex:inputhidden on a date field.  Since I was referencing this for client side validation, I made it an input type=hidden and it was no longer trying to bind it on upate.  Looks like things are working...

 

Well, as good as can be expected with me coding it :smileywink:

This was selected as the best answer