I have a platform event in my managed package. My_Platform_Event__e

I have a LWC that subscribes to it.

For this LWC to work in subscriber org, does my LWC need to include the namespace?


In my managed package development org, my LWC subscribes with:

subscribe('/event/My_Platform_Event__e', -1, messageCallback)

But the '/event/My_Platform_Event__e' is just a string, so I'm concerned it won't resolved to my namespace in subscriber org.

Do I need to update it to:

subscribe('/event/MY_NS__My_Platform_Event__e', -1, messageCallback)

Both of these approaches work in my managed package development org. But I don't know if they'll both work susbscriber org.

1 Answer 1


Turns out you absolutely have to include the namespace in the subscribe function.

ie. it must be:

subscribe('/event/MY_NS__My_Platform_Event__e', -1, messageCallback)

If you don't, you'll receive an error in your managed package LWC in the subscriber org when it attempts to subscribe:

    "clientId": "XXXXXXXX",
    "channel": "/meta/subscribe",
    "id": "YYY",
    "subscription": "/event/My_Platform_Event__e",
    "error": "403:denied_by_security_policy:create_denied",
    "successful": false
  • I am in the middle of trying to package a Platform Event with an LWC subscriber. I have found out my dev scratch orgs don't like the namespace prefix. (the subscribe function works with the namespace but unsubscribe does not) I plan on testing it but do you know if the subscriber org works with namespace for subscribe and unsubscribe? Looks like I might need to have a check in my code to see if its running in one of my dev orgs or a customer org and create the event API name accordingly. Importing the schema using LWC didn't help either for a few reasons.
    – Rory
    Aug 18, 2023 at 22:45
  • @Rory Not sure, maybe this other question I've added covers it? salesforce.stackexchange.com/questions/409956/…
    – Nick C
    Sep 6, 2023 at 3:04

You must log in to answer this question.

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