0

I'm new to LDS and I'd like to take advantage of this feature by limiting calls to the server. I'm able to view the proper field data, but having issues when it comes to updating the record. In the below code I have the Oppty.cmp on my Opportunity lightning record page. The idea is to display & update a couple of fields on the related Account record. I believe my components are properly set up, but I'm not too confident I am using my javascript function properly. Looking at the controller documentation here has not been helpful: https://developer.salesforce.com/docs/component-library/bundle/lightning:recordEditForm/example

account.cmp(related record)

 <!-- recordId is being set on the Opportunity component(passes in the Account Id) -->
 <aura:component implements="flexipage:availableForRecordHome,force:hasRecordId">
    <lightning:card title="Bill To Account">
        <lightning:recordEditForm recordId="{!v.recordId}"
                              aura:id="accountrecord"
                              objectApiName="Account"
                              onsubmit="!c.handleSubmit"
                              >

            <lightning:inputField fieldName="Comments__c" /> <!-- text field-->
            <lightning:inputField fieldName="Send_To_ERP__c" /><!-- checkbox -->
            <lightning:button class="slds-m-top_small" variant="brand" type="submit" name="save" label="Save" /><!-- no errors when clicking save  -->
        </lightning:recordEditForm><!-- the view form works so i know the recordId values are coming in-->
        <lightning:recordViewForm recordId="{!v.recordId}" 
                              objectApiName="Account"
                              >

            <lightning:outputField fieldName="Status__c" /><!-- Works as expected-->
            <lightning:outputField fieldName="Oracle_ERP_Account_Id__c" /><!-- Works as expected-->
        </lightning:recordViewForm>
    </lightning:card>
</aura:component>

account.jsController

({
        handleSubmit: function(cmp, event, helper) 
   {

        event.preventDefault();
        var eventFields=event.getParam("fields");
        eventFields["Comments__c"]="Test value";//does not set the value on the Account record
        cmp.find("accountrecord").submit(eventFields);
    }

  ref:https://salesforce.stackexchange.com/questions/225747/lightningrecordeditform-set-or-modify-field-values-onsubmit
});
0

I added an onclick attribute to my button and updated my javascript function:

<lightning:button class="slds-m-top_small" variant="brand" type="submit" name="update" label="update" onclick="{!c.update}" />


({

   update : function(component, event, helper) {
component.find("editRecord").submit();
   }

});
| improve this answer | |

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.