-1

I have a visualforce page where a user inputs serial numbers for an asset (New_Asset_Install_LOC_Serial_Number__c), I need this serial number input field to update the main serial number field on the asset Object (SerialNumber). Currently the New_Asset_Install_LOC_Serial_Number__c field is being updated on the asset, but I also need this value to populate the SerialNumber field on the asset.

Here is my visualforce code:

<apex:page docType="html-5.0" standardController="Case" extensions="installTicketUpdateAssetClass" id="thePage">
<apex:form id="theForm"> 
    <apex:pageblock id="Assets">

        <apex:pageBlockSection id="pbs" columns="1"> <!-- to allow the apex:input to show the label -->
            
            <apex:pageBlockTable rows="1" id="pbt3" value="{!Case.Assets__r}" var="asset">
            
                <apex:column style="width:12%;" headerValue="Product Code"><!-- to take the label dynamically -->
                     <apex:inputText style="width:80%;" disabled="true" styleClass="setupModelForId" value="{!asset.Product_Code_for_Paperless_Install_Docs__c}"  />
                </apex:column>
                
                <apex:column style="width:11%;" headerValue="ID Number"><!-- to take the label dynamically -->
                    <apex:inputText required="true" style="width:80%;" styleClass="idNumber" value="{!asset.New_Asset_Install_LOC_ID_Number__c}"  />
                </apex:column>
                
                <apex:column style="width:10%;" headerValue="B/W Starting Meter"><!-- to take the label dynamically -->
                    <apex:inputText required="true" styleClass="bwMeter" style="width:80%;" value="{!asset.New_Asset_Install_B_W_Meter__c}"  />
                </apex:column>
            
                <apex:column style="width:10%;" headerValue="Color Starting Meter"><!-- to take the label dynamically -->
                    <apex:inputText styleClass="colorMeter" style="width:80%;" value="{!asset.New_Asset_Install_Color_Meter__c}"  />
                </apex:column>
            
            <apex:column style="width:10%;" headerValue="I.P. Address"><!-- to take the label dynamically -->
                    <apex:inputText styleClass="ipAddress" style="width:90%;" value="{!asset.New_Asset_Install_Equipment_IP_Address__c}"  />
                </apex:column>
                
                <apex:column style="width:.01%;" headerValue=""><!-- to take the label dynamically -->
                    <apex:inputText disabled="true" style="width:.01%;" styleClass="setupIdNumber" value="{!asset.New_Asset_Setup_LOC_ID__c}"  />
                </apex:column>
            
        </apex:pageBlockTable>
            
            <apex:pageBlockTable id="pbt" value="{!Case.Assets__r}" var="asset">
                             
                <apex:column style="width:12%;" headerValue="Product Code"><!-- to take the label dynamically -->
                     <apex:inputText style="width:80%;" disabled="true" styleClass="setupModel" value="{!asset.Product_Code_for_Paperless_Install_Docs__c}"  />
                </apex:column>
                
                <apex:column style="width:12%;" headerValue="Serial Number Install"><!-- to take the label dynamically -->
                    <apex:inputText style="width:80%;" disabled="" styleClass="installSerialNumber" value="{!asset.New_Asset_Install_LOC_Serial_Number__c}"  />
                </apex:column>
                
                <apex:column style="width:6%; text-align:center;" value="{!asset.Serialized__c}"/>
                
                <apex:column style="width:13%;" headerValue="I Verified the Serial Number"><!-- to take the label dynamically -->
                    <apex:inputCheckbox styleClass="serialDoesntMatchCheckBoxOnAsset" value="{!asset.I_Verify_the_Serial_Number_is_Correct__c}"/>
                </apex:column>
                
                <apex:column style="width:.01%;" headerValue=""><!-- to take the label dynamically -->
                    <apex:inputText style="width:.01%;" disabled="true" id="pbi" styleClass="setupSerialNumber" value="{!asset.Serial_Number_Service_Setup__c}"  />
                </apex:column>
                
            </apex:pageBlockTable>
            </apex:pageBlockSection>
        
        
        
        <apex:pageBlockTable rows="1" id="pbt2" value="{!Case.Assets__r}" var="asset">
            
                <apex:column style="" headerValue="Location Remarks"><!-- to take the label dynamically -->
                    <apex:inputTextarea styleClass="locationRemarks" style="width:99.45%;" value="{!asset.New_Asset_Install_Equipment_Location__c}"  />
                </apex:column>
                
                <apex:column style="" headerValue="Install Notes"><!-- to take the label dynamically -->
                    <apex:inputTextarea styleClass="installNotes" style="width:99.45%;" value="{!asset.Install_Notes__c}"  />
                </apex:column>
            
                <apex:column headerValue="Customer DocuSign Link" >
                    <apex:outputLink target="_blank" style="width:99.45%;" value="{!case.Customer_DocuSign_Link__c}">
                        Customer DocuSign Link
                    </apex:outputLink>
                </apex:column>
            
        </apex:pageBlockTable>
        
        <apex:pageBlockSection id="pbs2" columns="2">
            <apex:inputField id="cheaterOnSite" onchange="cheaterLeftOnSite(); return false;" value="{!case.Cheater_Left_On_Sight__c}"/>
            <apex:inputCheckbox styleClass="autoSerialCheck" onchange="" id="serialNumberVerified" disabled="" value="{!Case.Serial_Numbers_Verified__c}"/>
            <apex:inputText id="cheaterId" value="{!case.Cheater_ID__c}"/>
            <apex:inputCheckbox onchange="enableUpdateButton(); return false;" id="manualSerialNumberVerification" disabled="" value="{!Case.Manual_Serial_Number_Verification__c}"/>
            <apex:inputCheckbox id="cheaterCheckBox" value="{!case.Cheater_was_used_at_install__c}"/>
            <apex:inputCheckbox id="install" value="{!Case.Install_Complete__c}"/>
            
          
            
        </apex:pageBlockSection>
        <p class="serialDoesntMatch">
            <apex:inputCheckbox id="serialDoesntMatchCheckBox" value="{!Case.Asset.I_Verify_the_Serial_Number_is_Correct__c}"/> 
            The above serial number(s) have been verified by <strong>{!$User.FirstName} {!$User.LastName}.</strong>
            <br/>
            <strong>{!$User.FirstName} {!$User.LastName}</strong> has uploaded a document that verifies the correct serial number
           
        </p>
        <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}" />
        </apex:pageBlockButtons>
    </apex:pageblock>
</apex:form>
</apex:page>

And here is my apex class:

public class installTicketUpdateAssetClass {
        private ApexPages.StandardController controller;
    
        //Constructor 
        public installTicketUpdateAssetClass(ApexPages.StandardController controller) {
            this.controller = controller;
        }
    
        public void saveSerialIdNumber() {
            // here we use the standard controller's capability of fetching related records to update them ourselves 
            // (Casting is needed because YourChildRelationshipName__r is specific to your case object)
            update ((Case) controller.getRecord()).Assets__r;
            // here we call the standard controller's "update"
            controller.save();
        }
}

Any help would be greatly appreciated

0

You can't point a Visualforce input field at more than one underlying data field. You'll need to either write Apex code to iterate over Case.Assets__r before you perform your update to assign the value to SerialNumber, or build business process automation (Apex trigger, or your declarative tool of choice) to apply this rule globally by populating all updates to New_Asset_Install_LOC_Serial_Number__c into SerialNumber.

0

I solved this by updating the save button in my class:

public class installTicketUpdateAssetClass {
private ApexPages.StandardController controller;


public installTicketUpdateAssetClass(ApexPages.StandardController controller) {
    this.controller = controller;
}

public void saveSerialIdNumber() {

    for(Asset assetObj : (list<Asset>) ((Case) controller.getRecord()).Assets__r){
        assetObj.SerialNumber = assetObj.New_Asset_Install_LOC_Serial_Number__c;
    }
    update ((Case) controller.getRecord()).Assets__r;
   
    controller.save();
}

}

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.