0

I have created a Lightning Aura component to redirect a quick action that creates a record to the newly created record. This message shows up after the record is created and the user goes into edit and save.enter image description here

<aura:component implements="flexipage:availableForAllPageTypes">
    <aura:dependency resource="markup://force:navigateToSObject" type="EVENT"/>
    <aura:handler event="force:showToast" action="{!c.redirectToNewRecord}"/>
</aura:component>
({
    redirectToNewRecord: function(component, event, helper) {
        var messageData = event.getParam('messageTemplateData');
        if (!$A.util.isEmpty(messageData)) {
            var executionComponent = messageData[1].executionComponent;
            if (!$A.util.isEmpty(executionComponent)) {
                var recordId = executionComponent.attributes.recordId;
                var navEvt = $A.get("e.force:navigateToSObject");
                navEvt.setParams({
                    "recordId": recordId,
                    "slideDevName": "related"
                });
                navEvt.fire();
            }
        }
    }
})

1 Answer 1

1

This issue is because messageData doesn't have a value at its second index (messageData[1]). Have you tried using the first index (messageData[0])? If you are always expecting two items in the messageData array, maybe you are better off checking that its length is 2 instead of checking if it is not just empty.

// check first index
var executionComponent = messageData[0].executionComponent;

// OR ensure the length is at least 2
if (!$A.util.isEmpty(messageData) && messageData.length > 1) {
    var executionComponent = messageData[1].executionComponent;
    // ...
}
1
  • 1
    To add to this answer bascially the error is telling you that messageData[1] is undefined and you are trying to reference it. You will either want to validate it on the client or better yet validate it on the server before you even send it back. Dec 19, 2020 at 2:51

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.