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.
import STATUS_FIELD from '@salesforce/schema/namespace__BatchExportEvent__e.namespace__Status__c
c__
?