You need to sign in to do that
Don't have an account?
Save button on a VF Page not saving/updating
I created a VF Page using a standard controller and a custom extension. My purpose for this VF Page is to update fields on a specific record within a custom object, but for some reason it is not updating the record once I enter in the data and click on the save button.
BELOW IS MY CONTROLLER AND EXTENSION:
public class SupplierInfoExtension{
public order__c selectedOrder {get;set;}
public List<Order_Line_Item__c> selectedOrderLines {get;set;}
public SupplierInfoExtension(ApexPages.StandardController controller) {
selectedOrder = (Order__c) controller.getRecord();
selectedOrderLines = [SELECT Additional_Information__c, Approx_Lbs_Gal__c, CreatedById, CreatedDate, FOB_DVD_Customer__c, FOB_DVD_Supplier__c,
Id, Name, Order__c, Product__r.name, Product_Code__c, Customer_Product_Code__c
FROM Order_Line_Item__c
WHERE Order__c = : selectedOrder.Id];
}
public void save()
{
update selectedOrder;
}
}
BELOW IS MY VF PAGE CODE:
<apex:page sidebar="false" StandardController="Order__c" extensions="SupplierInfoExtension">
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!Order__c}" var="Order">
<apex:column value="{!Order__c.name}"/>
<apex:column value="{!Order__c.customer__r.name}"/>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="save" action="{!save}"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!selectedOrderLines}" var="ol">
<apex:column headerValue="Product Code">
<apex:inputField value="{!ol.Product_Code__c}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Any thoughts on why the record is not updating?
BELOW IS MY CONTROLLER AND EXTENSION:
public class SupplierInfoExtension{
public order__c selectedOrder {get;set;}
public List<Order_Line_Item__c> selectedOrderLines {get;set;}
public SupplierInfoExtension(ApexPages.StandardController controller) {
selectedOrder = (Order__c) controller.getRecord();
selectedOrderLines = [SELECT Additional_Information__c, Approx_Lbs_Gal__c, CreatedById, CreatedDate, FOB_DVD_Customer__c, FOB_DVD_Supplier__c,
Id, Name, Order__c, Product__r.name, Product_Code__c, Customer_Product_Code__c
FROM Order_Line_Item__c
WHERE Order__c = : selectedOrder.Id];
}
public void save()
{
update selectedOrder;
}
}
BELOW IS MY VF PAGE CODE:
<apex:page sidebar="false" StandardController="Order__c" extensions="SupplierInfoExtension">
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!Order__c}" var="Order">
<apex:column value="{!Order__c.name}"/>
<apex:column value="{!Order__c.customer__r.name}"/>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="save" action="{!save}"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!selectedOrderLines}" var="ol">
<apex:column headerValue="Product Code">
<apex:inputField value="{!ol.Product_Code__c}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Any thoughts on why the record is not updating?
Controller Extension:
VF page:
All Answers
public class SupplierInfoExtension{
public order__c selectedOrder {get;set;}
public List<Order_Line_Item__c> selectedOrderLines {get;set;}
public SupplierInfoExtension(ApexPages.StandardController controller) {
selectedOrder = (Order__c) controller.getRecord();
selectedOrderLines = [SELECT Additional_Information__c, Approx_Lbs_Gal__c, CreatedById, CreatedDate, FOB_DVD_Customer__c, FOB_DVD_Supplier__c,
Id, Name, Order__c, Product__r.name, Product_Code__c, Customer_Product_Code__c
FROM Order_Line_Item__c
WHERE Order__c = : selectedOrder.Id];
}
public void dosave()
{
update selectedOrder;
}
}
<apex:commandButton value="save" action="{!dosave}"/>
Another strange thing is 2 of the fields are required in the VF page, but when I look at them in the custom object they are not required. That is really strange.
Any thoughts?
Also, could you pls explain what the exact requirements are? Are you trying to update order and order line item at the same time? Just want to understand the use case...
I am trying to update the order line items at the same time on one page, so I dont have to keep clicking from one line item to the next.
Controller Extension:
VF page:
Please mark as Best Answer so that it can help others!