Is it possible to fire a PE from within LWC without needing an Apex controller by using createRecord
UI API?
Here is what I have as a headless quick-action component
import { createRecord } from "lightning/uiRecordApi";
import HeadlessQuickAction from "c/headlessQuickAction";
import PE_OBJECT from "@salesforce/schema/MY_Platform_Event__e";
export default class MyHeadlessAction extends HeadlessQuickAction {
connectedCallback() {
this.setHeadlessActionFunction(this.share);
}
share() {
const fields = {};
fields.Field1__c = "field one value";
fields.Field2__c = JSON.stringify({
aa: "test",
bb: "test",
cc: "test"
});
const recordInput = { apiName: PE_OBJECT.objectApiName , fields };
createRecord(recordInput)
.then((response) => {
console.log("Event published successfully", response);
})
.catch((error) => {
console.error("Error publishing event:", error);
});
}
}
There are 2 problems with this;
PE_OBJECT.objectApiName
always givesMY_Platform_Event__c
and NOTMY_Platform_Event__e
- When I hardcode the value correctly, that is
MY_Platform_Event__e
, this time the execution seems to go through the server and gives the following error
body:
errorCode: "ENTITY_NOT_QUERYABLE"
message: "Unable to view record since MY_Platform_Event__e is not queryable."
statusCode: 403```