2

I'm trying to make a component in a managed package to subscribe to a certain platform event, and referencing the channel with its API name previously worked:

import BATCH_EVENT_NAME from '@salesforce/schema/BatchExportEvent__e'

subscribe('/event/BatchExportEvent__e', -1, eventCallback).then(response => {
       component.subscribed = true
       component.subscription = response
})

But trying to use ${BATCH_EVENT_NAME.objectApiName} to subscribe "dynamically" to the event, doesn't work. The framework returns a BatchExportEvent__c string (note the c suffix, instead of the e, for events).

Hardcoding the BatchExportEvent__e to the subscription seems to solve the issue in a development environment. However, I need to access the event's fields as well. So of course I tried to add those fields using the import syntax as well. For example:

import STATUS_FIELD from '@salesforce/schema/BatchExportEvent__e.Status__c'

And, again, development went smoothly. But when trying to install a package version in a development environment, I get the error:

exportData: Invalid reference BatchExportEvent__c.JobItemsProcessed__c
of type sobjectClass in file exportData.js

Notice, once more, the issue with the suffix. The platform appends c instead of e. I'm not even sure if this is the issue here anymore.

Is there a guide on how to use platform events within managed packages, and accessing them in the component?


Like mentioned in the comments, if I try to add the namespace manually I get the following message while pushing the code to the scratch org:

force-app/main/frontend/lwc/exportData/exportData.js  LWC1504:
Invalid module id "x__BatchExportEvent__e.x__AsyncApexJobId__c"
for type "schema". Explicit use of namespace "x" in file 
"exportData.js" is prohibited. Use default namespace "c" instead.
  • Would adding your namespace to the object and field name be any helpful? import STATUS_FIELD from '@salesforce/schema/namespace__BatchExportEvent__e.namespace__Status__c – Raul May 11 at 23:00
  • If I remember correctly the platform doesn’t allow me to save it if I specify the namespace. I only got the error for apex classes though, so I need to check this with objects and platform events. – Renato Oliveira May 11 at 23:02
  • 1
    I've updated the question with what happens when I attempt to add the namespace explicitly, @Raul. – Renato Oliveira May 12 at 11:32
  • Oh damn, and does it allow us to use namespace c__? – Raul May 12 at 12:15
  • It is not possible to specify a c__ namespace. It doesn't exist. You would get an "invalid reference of type" error. – Renato Oliveira May 14 at 14:21

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.