+ Start a Discussion
Ian DoneyIan Doney 

Need help with Visualforce page save button

I have a visualforce page on the Workorder object that lists out all of the assets on an order. A user will fill out some input fields and click the update button. This saves all of the input fields to the related asset. There are also cases related to the assets that I need to update as well. I am able to show the fields from the related case that is related to the asset on the visualforce page, but I can't figure out how to get my save button to save the info for the related case. So basically the relationship goes WorkOrder > Asset > Case.

Here is my visualforce code:
<apex:form id="theForm"> 
        <apex:pageblock id="Assets">
                <apex:pageBlockTable rows="" id="pbt0" value="{!WorkOrder.Assets__r}" var="asset">
                    <apex:column rendered="{!asset.SBQQ__RequiredByAsset__c == null}" style="width:16.66666666666667%;" headerValue="Product Code"><!-- to take the label dynamically -->
                  		<apex:inputText style="width:94%;" disabled="true" styleClass="setupModelForId" value="{!asset.Product_Code_for_Paperless_Install_Docs__c}"></apex:inputText>
                    <apex:column rendered="{!asset.SBQQ__RequiredByAsset__c == null}" style="width:20%;" headerValue="ID Number"><!-- to take the label dynamically -->
                    	<apex:inputText onchange="updateIdNumber(); return false;" style="width:94%;" styleClass="idNumber" value="{!asset.New_Asset_Install_LOC_ID_Number__c}"  />
                    <apex:column rendered="{!asset.SBQQ__RequiredByAsset__c == null}" style="width:16.66666666666667%;" headerValue="B/W Meter"><!-- to take the label dynamically -->
                    	<apex:inputText required="true" styleClass="bwMeter" style="width:94%;" value="{!asset.New_Asset_Install_B_W_Meter__c}"  />
                    <apex:column rendered="{!asset.SBQQ__RequiredByAsset__c == null}" style="width:16.66666666666667%;" headerValue="Color Meter"><!-- to take the label dynamically -->
                    	<apex:inputText styleClass="colorMeter" style="width:94%;" value="{!asset.New_Asset_Install_Color_Meter__c}"  />
                    <apex:column rendered="{!asset.SBQQ__RequiredByAsset__c == null}" style="width:16.66666666666667%;" headerValue="I.P. Address"><!-- to take the label dynamically -->
                    	<apex:inputText styleClass="ipAddress" style="width:94%;" value="{!asset.New_Asset_Install_Equipment_IP_Address__c}"  />
                    <apex:column style="width:16.66666666666667%;" rendered="{!asset.SBQQ__RequiredByAsset__c == null}" headerValue="Install Date">
                    	<apex:inputField id="installDate" styleClass="installDate" value="{!asset.New_Equipment_Setup_and_Install_Ticket__r.Install_Date__c}"/>
                     <apex:column style="width:16.66666666666667%;" rendered="{!asset.SBQQ__RequiredByAsset__c == null}" styleClass="" headerValue=""><!-- to take the label dynamically -->
                            <apex:inputText disabled="true" style="" styleClass="setupIdNumber" value="{!asset.New_Asset_Setup_LOC_ID__c}"  />
			<apex:pageBlockButtons location="bottom">  
                <apex:commandButton styleClass="verify" id="verify" onclick="verifySerialNumbers(); return false;" value="Verify" />
                <apex:commandButton oncomplete="congrats(); return false;" styleClass="update" id="update" disabled="" value="Update" action="{!saveSerialIdNumber}" />

And here is my class:
public class installUpdateAssetWorkOrderClass {

    private ApexPages.StandardController controller;
    public List<WorkOrderLineItem> WorkOrderLineItems{get;set;}

    public List<WorkOrderLineItem> WorkOrderLineItemsSupplies{get;set;}
    public List<Asset> Assets{get;set;}
    public List<Case> Cases{get;set;}
    public WorkOrder WorkOrders {get;set;} 

    public WorkOrder wo {get;set;} 



     public installUpdateAssetWorkOrderClass(ApexPages.StandardController controller) {
        this.controller = controller;

        wo = (WorkOrder)controller.getRecord();      
        WorkOrders = [SELECT id FROM WorkOrder WHERE id=: wo.id LIMIT 1]; 

         Assets = [SELECT id, New_Equipment_Setup_and_Install_Ticket__r.Install_Date__c, Product2.Serialized__c, New_Equipment_Setup_and_Install_Ticket__c, Show_in_MultiMachine_Delivery_Acceptance__c,SerialNumber,Name,Delivery_Address__c,Product_Code_Display__c,Product_Description_Display__c FROM Asset where Work_Order__c = :WorkOrders.id]; 
     	Cases = [SELECT id, Cheater_Left_On_Sight__c FROM Case WHERE Work_Order__c = :WorkOrders.id];
    //save button for serial number
    public void saveSerialIdNumber() {
        // This will copy the values from custom field to Serial Number field 
		for(Asset assetObj : (list<Asset>) ((WorkOrder) controller.getRecord()).Assets__r){
			assetObj.SerialNumber = assetObj.New_Asset_Install_LOC_Serial_Number__c;
        update ((WorkOrder) controller.getRecord()).Assets__r;
        // here we call the standard controller's "update"

I know there is nothing in my class telling the save button to save anything on the Case object. But I have tried numerous different things and I can get the class to save.

Any help would be greatly appreciated.

Thank you.
ShirishaShirisha (Salesforce Developers) 
Hi Ian,


If you have any insert operations in a method then you can use it on the button as action.

If you have the method "saveSerialIdNumber()" which performs the Save action then you can call it on the CommandButton as below:
<apex:commandButton action="{!saveSerialIdNumber}" value="Save"/>


Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
Ian DoneyIan Doney
Hi Shirisha,

So I do actually call the "saveSerialIdNumber()" method:
<apex:commandButton oncomplete="congrats(); return false;" styleClass="update" id="update" disabled="" value="Update" action="{!saveSerialIdNumber}" />

But this only saves the inputs that I have on the Work Order and the Asset. It doesn't save any inputs on the Cases that are related to the Assets.
Is there something I am missing to get this to save the inputs on the Cases that are related to the Assets?