2

Ok, this has been driving me nuts for the past couple of hours and I'm at my wits end. I created a custom application event in a sandbox and deployed it to production. In the sandbox I can call it all day long with no issues. In production I keep getting an undefined value when I use the $A.get function.

I have tried creating a new event "MassUpdate2" directly in production and I can't call it either.

I literally copy and paste the same code that I added into the helper class into production and input it into the same helper class in the sandbox and everything works just fine and dandy.

I've got a total of 3 application events and none of them are being returned when called.

For a little bit of background, the whole reason I have these events is for the functionality that's included as a part of Enhanced Lightning Grid. It has the ability to define actions, which calls application events. I kept getting an error in production, "Invalid event name - cannot identify event". Thus my investigation.

Again, in the Sandbox everything is just fine and dandy. I didn't do the lightning deployment for this org, so I've got to wonder if there's a setting that the previous consultants didn't set? I've done a ton of lightning development and have not run into this before.

Code:

<!--c:MassUpdate.evt-->
<aura:event type="APPLICATION" description="Event will obtain information to push a mass update" access="global">
<aura:attribute name="recordIDs" type="List" access="global" required="true" description="The Id's to update" />
<aura:attribute name="entityApiName" type="String" access="global" required="false"  description="The API Name of the object to update" />
<aura:attribute name="fieldSetApiName" type="String" access="global" required="false"  description="The API Name of the fieldset with " />
<aura:attribute name="fieldsToDefaultValues" type="Map" access="global" required="false" description="The API Names of the fields with the default value defined for the update, provid in JSON format"  />

Test helper:

({
    initialize : function(component, event, helper) {
        var appEvent = $A.get('e.c:MassUpdate');
        console.log('appEvent MassUpdate:');
        console.log(appEvent);
    }
})

In production the console returns undefined. In the sandbox it returns the expected object.

Assumptions

For starters, I am not using a namespace. This is a regular production org not a dev instance. Thus when I call e.c, it's the correct namespace. Most of the other questions I've seen around this topic have to do with a namespace issue. This is not the case here since you have to have a developer org to have a namespace.

I also don't think this is a callback issue, because again it works in the Sandbox. If it was a callback issue (which is another one of the items I've reviewed), it would presumably happen in the sandbox as well.

Troubleshooting steps and items checked

  • I have checked to make sure that the session settings are the same in sandbox and production (just in case).
  • The critical updates are also in parallel.
  • I also tried setting the API version of the event to 40 just incase it was a bug introduced with Winter 19.
  • For giggles and grins I tried switching the event from global to public
  • I have tried taking out all attributes and just making it a basic event
  • Tested it in the Sales console and outside of it, same result
  • Tried different objects (the object I'm trying this on is a managed object, so just in case I used Contact instead)
  • Tried using the controller instead of the helper

Does anyone have any other bright ideas? It could be due to the late hour, but I'm honestly at a loss for what else this could be.

2
  • Can you include the component markup in your question? Does it have <aura:registerEvent name="massUpdate" type="e.c:MassUpdate"/> in it? If not, maybe Lightning doesn't know that it needs that event client-side, so it can't find it.
    – Aidan
    Commented Nov 13, 2018 at 10:22
  • Thanks Aidan, you helped kick loose the issue in the back of my head. It was a deployment issue, the listener component didn't deploy on the record page like it was supposed to. Was too tired to catch it doh Commented Nov 13, 2018 at 21:10

1 Answer 1

0

Ok, this was a combination of the late hour combined with a rather large deployment with a deployment that didn't bring everything over for some reason. @Aidan thanks for the comment, it helped jar this free from the back of my mind.

It had been a few months since I developed this solution so it must have gotten hard archived in my mind and I made an assumption that everything made it over on the lightning record page.

There was a component that I had added to the page that listened and handled all "Custom Events" that the enhanced lightning grid used for "actions".

I had forgotten about this when I deployed the pages because it had been added to each of the record pages in the sandbox and should have been there post deployment. For some reason the component didn't get added to the page as it should have when it was deployed from the sandbox using the metadata API, and I was too tired to remember to check for it.

For those who may run into a similar issue (and my self since my memory obviously cannot be trusted lol), here is a more detailed explanation of what I forgot and why it's important.

There was a lightning component that handled all of the custom application events. In this case let's call it "VisualGridHelper". I added this custom component to a spot in the Lighting Record Page that ensures that it stays loaded (below the primary tab component).

It does not need to be "visible" (meaning no real markup, which is probably why I didn't notice it wasn't there post deployment), just loaded on the page. The component essentially dynamically generates or removes the appropriate components when the appropriate event was is called.

When you use an out of the box application event, the handlers are loaded within the SFDC standard library that's loaded with the Lightning framework. Thus you don't have to worry about handling the event, Salesforce already knows how to listen and handle the event.

For this example, I'm going to focus on a couple of events, one that generates a modal and one that closes it.

The component

<!--VisualGridHelper.cmp-->
<aura:component implements="flexipage:availableForAllPageTypes,flexipage:availableForAllPageTypes,force:hasRecordId" access="global">
    <lightning:overlayLibrary aura:id="VisualGridHelperOverlayLib"/>
    <aura:handler event="c:MassUpdate" action="{!c.doMassEdit}"/>
    <aura:handler event="c:CloseModal" action="{!c.doModalClose}"/>
</aura:component>

The controller

//VisualGridHelperController.js
({
    doMassEdit : function(component, event, helper) {
        var ids = event.getParam('recordIDs');
        var fieldsToDefaultValues = event.getParam('fieldsToDefaultValues');
        var modalBody;
        $A.createComponent("c:massUpdateModal", {
            'entityApiName':'CustomObject__c',
            'fieldSetApiName':'CustomObjectFieldSetMassUpdate',
            'fieldsToDefaultValues':fieldsToDefaultValues,
            'ids':ids
            },
           function(content, status) {
               if (status === "SUCCESS") {
                   modalBody = content;
                   component.find('VisualGridHelperOverlayLib').showCustomModal({
                       header: "Mass Update",
                       body: modalBody, 
                       showCloseButton: true,
                       cssClass: 'slds-modal_medium',
                       closeCallback: function() {}
                   })
               }                               
           });
    },
    doModalClose : function(component, event, helper) {
        component.find('VisualGridHelperOverlayLib').notifyClose();
    },
})

So essentially VisualGridHelper component on the lightning app page is there to "listen" for an action initiated by the Visual Grid component. When that action is initiated the listener kicks off the modal and displays it on the page.

I don't know why I didn't think about this portion having not transitioned over as a part of the lightning page during deployment other than simple tiredness. This component not being present on the record page was the reason why the application event was returning as undefined.

So lesson learned, always makes sure that you double check that all custom components added to Lightning Record Pages in the sandbox are present after you deploy to a new environment!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .