1

I have overridden standard Edit button with a Custom Lightning Component and that component is using force:recordEdit component in it to allow user edit the record.

I have a custom save method implemented in my component that is pretty much similar to example documented at Salesforce Lightning component reference.

The line in my save method cmp.find("edit").get("e.recordSave").fire(); is working very weirdly. Sometimes it is working fine and saving the record and sometimes throwing bellow error.

enter image description here

Here is the code implemenation for this:

Component Code:

<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<aura:handler name="onSaveSuccess" event="force:recordSaveSuccess" action="{!c.handleSaveSuccess}"/>

<div id="slds-modal__DCamp" aura:id="slds-modal__DCamp">
    <section role="dialog" tabindex="-1" aria-labelledby="modal-heading-01" aria-describedby="modal-content-id-1" class="slds-modal slds-slide-up-saving">
        <div class="slds-modal__container">
            <header class="slds-modal__header">
                <lightning:buttonIcon iconName="utility:close" variant="bare" onclick="{! c.cancelEdit }"  class="slds-button slds-button_icon slds-modal__close slds-button_icon-inverse slds-button_icon-small" alternativeText="Close window."/>
                <h2 id="modal-heading" class="slds-text-heading_medium slds-hyphenate">Edit {!v.recordName}</h2>
            </header>
            <div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1">
                <force:recordEdit aura:id="edit" recordId="{!v.recordId}"/>
            </div>
            <footer class="slds-modal__footer">
                <lightning:button variant="neutral" label="Cancel" onclick="{! c.cancelEdit }" />
                <lightning:button variant="brand" label="Save" onclick="{! c.save }" />
            </footer>
        </div>
    </section>
    <div class="slds-backdrop slds-backdrop_open" style="visibility: visible;opacity: 1;"></div>
</div>

Controller.js

save : function(cmp, event) {
    cmp.find("edit").get("e.recordSave").fire();
    console.log('----> inside save.');
},
handleSaveSuccess : function(cmp, event) {
    // Display the save status
    var toastEvent = $A.get("e.force:showToast");
    toastEvent.setParams({
        "type" : "Success",
        "mode" : "dismissible",
        "duration" : 5000,
        "message": "Record "+cmp.get("v.recordName")+" was saved."
    });
    toastEvent.fire();
    var  viewURL = "/"+cmp.get("v.recordId");
    var urlEvent = $A.get("e.force:navigateToURL");
    urlEvent.setParams({
        "isredirect" : false,
        "url": viewURL
    });                        
    urlEvent.fire();
}

Any idea, why it is behaving like this? any help on this will be greatly appreciated.

  • Try to debug it: separate the line: var editCmp = cmp.find("edit"); and then var recSave = editCmp.get("e.recordSave"); and then recSave.fire(); now use chrome dev tools and put a breakpoint in the begining of the method and see what is returning null and when – Itai Shmida Aug 15 '17 at 5:56
  • I have already tried it. It just return {}. Nothing else. – thatherahere Aug 15 '17 at 8:15
  • Did you ever find out why get("e.recordSave") is returning null? Facing the same problem. – Daniel Flippance Sep 19 '17 at 18:39
  • no @DanielFlippance. Its weird. – thatherahere Sep 19 '17 at 19:20
  • @thatherahere I've just noticed that immediately after I upload a new change to Salesforce and refresh the browser, get("e.recordSave") returns a good object. If I then do some testing in the browser and force a browser refresh again without deploying to Salesforce, get("e.recordSave") then always returns null. Then every time I deploy a new build to Salesforce, get("e.recordSave") comes back with a good object – Daniel Flippance Sep 19 '17 at 20:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.