I've got a LWC embedded on a lightning page for the SBQQ__Quote__c object. It's subscribing to a platform event channel. I have a trigger setup on Opportunity (parent object of SBQQ__Quote__c) that's publishing the platform event based on certain criteria. Is there a way to limit the platform event subscription in the LWC so that it will only subscribe to the platform event if the event is related to the parent Opportunity record? Currently if I trigger the event from an Opportunity and I have unrelated Quote records open, they're all subscribing to the event. Ideally I'd like to have only Quotes related to the Opportunity be subscribed. If this isn't possible, maybe there's a way to filter within the subscribe method so that the callback doesn't run for these unrelated Quotes? I'm thinking possibly something along the lines of setting a Text field on the PE while publishing that will get stamped with the current Opportunity ID, then referencing this value inside of the LWC (ie: If the Quote's OppId == the Opp ID field on the PE). I had been trying similar attempts at this a few days ago and was unsuccessful, so any advice would be really helpful.
Here's my platform event functionality inside of the LWC:
import { subscribe, unsubscribe, onError, setDebugFlag, isEmpEnabled } from 'lightning/empApi';
export default class OpportunityContactRoles extends LightningElement {
subscription = {};
@api channelName1 = '/event/PO_Received_Message__e';
connectedCallback() {
this.handleSubscribe();
}
disconnectedCallback() {
this.handleUnsubscribe();
}
handleSubscribe() {
const callbackMessage = (response) => {
this.displayStopSign = true;
updateQuoteRecord({quoteId: this.recordId}).then((response) => {
this.booleanVariable = true;
this.dispatchEvent(new RefreshEvent());
})
}
subscribe(this.channelName1, -1, callbackMessage).then(response => {
console.log('Subscription request sent to: ', JSON.stringify(response.channel));
})
}
handleUnsubscribe() {
unsubscribe(this.subscription, response => {
console.log('unsubscribe() response: ', JSON.stringify(response));
});
}
}