0

I have a Lightning Component PortalHeader

PortalHeader.cmp looks like this:

<aura:component controller="currentUserInfoCtrl" description="portalHeader" implements="forceCommunity:availableForAllPageTypes" access="global">
<aura:attribute name="userInfo" type="user"></aura:attribute>
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>

<div id="ui-wrapper">
    <div class="container">
...

PortalHeaderController.js:

({
doInit: function(component, event, helper) {

    var action = component.get("c.fetchUser");
    ...
    window.addEventListener("message", function(event) {
        doInit();
    });
 },

and I am getting an error:

doInit is not defined throws at https://.../AP/s/components/c/PortalHeader.js:30:17

Please note:

  1. doInit is right there in the PortalHeaderController.js
  2. There is no PortalHeader.js file there is PortalHeaderController.js and PortalHeaderHelper.js

Any idea of what is going on here and why am I getting this error?

Thank you very much!

4
  • This could be a result of Salesforce caching. If this is in a sandbox, go to Setup -> Session Settings and search for a setting named "Enable secure and persistent browser caching to improve performance" and turn it off. If it's a production instance, just mash Ctrl+Shift+R until it goes away. Jul 24, 2021 at 2:20
  • @DrewKennedy No that's not it. it happens on several machines to several users over multiple days. Thanks anyway!
    – shlasasha
    Jul 26, 2021 at 13:30
  • Can you share the full file for PortalHeader.js Jul 26, 2021 at 14:42
  • This is an example of why chopping out too much code for an example can sometimes obscure the problem. That second doInit call wasn't in the original example :) Jul 27, 2021 at 18:47

1 Answer 1

1

Problem was doInit is called within itself. Trick is to move all the initialization to the Helper file And then call it once from doInit and again from the event

({
    doInit : function(component, event, helper) {
        helper.initHelper(component);

        window.addEventListener("message", function(event) {
              helper.initHelper(component);
        });        
  },

You must log in to answer this question.

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