I’m working on a managed package. While testing a beta version in a sandbox, I’ve noticed that my LWC failed to subscribe to a platform event. The reason was that I didn’t specify the namespace prefix while subscribing. Adding the prefix fixed the issue.

But then I wondered: why the same logic works perfectly in a namespaced scratch org, where I tested before installing to the sandbox?

This is the only platform event in the scratch org. enter image description here

But subscription to this channel /event/Toast__e works just fine.

import { subscribe, unsubscribe, onError } from 'lightning/empApi';

subscribe('/event/Toast__e', -1, toastCallback)
   .then(response => {

Does anyone have an idea why?

  • 1
    My tuppence: to find the "why" you would need insider knowledge, so would have to get detail from Salesforce. It is as it is and this is one of many ISV learning points you should note and share with your team.
    – Phil W
    Commented May 7 at 14:08
  • @PhilW I agree. Perhaps someday someone with that knowledge will see the question:) Thank you for your comment. Commented May 8 at 10:27


You must log in to answer this question.