2

I'm currently facing a really strange behaviour during Lightning component developement.

I created a react app that runs inside a simple lightning component, which only provides the style and script resources and a react doot div.

To make it more comfortable to fire events, I built a small helper class that exports a single fire method and wraps the standard Aura framework:

    /**
     * Event helper class that provides environment to
     * use Aura event handling API inside react.
     */
    const EventHelper = (() => {

      let service = {};

      /**
       * Fires an aura event.
       *
       * @param event Name of the event to be fired
       * @param data Event payload or configuration for event
       */
      service.fire = (event, data) => {

        console.log(event, data);

        // receive event from aura component
        let eventObject = $A.get('e.' + event);

        console.log(eventObject);

        // if event exists, try to set params and fire
        if(eventObject) {
          console.log('Firing: ', event, eventObject);
          data && eventObject.setParams(data);
          eventObject.fire();
        } else {
          console.log('abort firing');
        }
      };

    return service;
  }
})();

export default EventHelper;

This class works fine. Eg. I want to emit force:showToast with it's params, I just need to call:

EventHelper.fire('force:showToast', {
   title: 'Toast Title',
   message: 'Toast message'
});

This works well, the toast appears with the title and the message.

But now, I want to navigate to a specific record. Following the Dev documentation, the event is 'force:navigateToSObject'.

When I now change the call of my event helper to:

EventHelper.fire('force:navigateToSObject', {
   recordId : '%ID of my Record'
});

All outputs are working, and even the lightning developer console for chrome indicates that the event was being fired:

Indicator that event was fired

But... Nothing happens...

When I fire this event directly from the component js controller, it works.

I came across a same behaviour with the ui:showDatePicker event.

Does anyone have experienced a similar behaviour of some lightning component events?

Thanks in advance! Cheers

Flo

  • Any luck with wrapping the function of service.fire inside of $A.getCallback ?. Something like service.fire = $A.getCallback(function(event, data) {..}) – Praveen Apr 9 '17 at 15:19
  • Hey Praveen, thanks. But i had no luck with this. As I said, other events (like force:showToast oder force:editRecord) are working with my implementation. – Florian Gümbel Apr 10 '17 at 9:47

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.