I'm firing platform event from an LWC component when a record is updated from tab 1 and subscribing to that event in tab 2 to get the latest updates. The published events shows correctly however, it's exceeding the daily limit for event deliveries.
For example if we published 1000 events, its delivering 40,000 events.
Is there a way to check why there are duplicate deliveries for a single published event?
Below is code that I have in tab 1 and tab 2. Thanks!
Tab 1 :
updateDetails() {
const fields = {};
const recordInput = { fields };
updateRecord(recordInput)
.then(() => {
this.firePlatformEvent();
this.dispatchEvent(
new ShowToastEvent({
title: 'Success',
message: 'Record Updated',
variant: 'success'
})
);
})
.catch(error => {
this.dispatchEvent(
new ShowToastEvent({
title: 'Error updating record',
message: error.body.message,
variant: 'error'
})
);
});
}
firePlatformEvent(){
fireEvent({message:'success',caseId: this.Case__c});
}
Tab 2 :
connectedCallback() {
this.registerErrorListener();
this.handleSubscribe();
}
handleSubscribe() {
const self = this;
const messageCallback = function (response) {
var platformEventOwner = response.data.payload.CreatedById;
if(USER_ID == platformEventOwner && response.data.payload.CaseId__c == self.recordId){
self.showComponent = false;
const myTimeout = setTimeout(() => {self.showComponent=true;}, 50);
}
};
// Invoke subscribe method of empApi. Pass reference to messageCallback
subscribe(this.channelName, -1, messageCallback).then(response => {
// Response contains the subscription information on subscribe call
console.log('Subscription request sent to: ', JSON.stringify(response.channel));
this.subscription = response;
});
}