I have the following flow, LWC -> Apex (REST API) -> Inserts data in some_object__c -> Trying to refresh the LWC which is based on the some_object__c.
I have a platform event(PE) which fires when data is inserted in the some_object__c via a process builder. I am subscribing to the PE in LWC using, once the PE is fired I can see the console log, upto this point everything is working, now if you see my commented out code, I am trying to query the apex class to give me the data from some_object__c, it is showing me old data and not the newly inserted data.
Question: How can I get the most recent data in my LWC ? I cannot use @wire that annotation fails.
import { subscribe, unsubscribe, onError, setDebugFlag, isEmpEnabled } from 'lightning/empApi';
import getSegmentMemberships from '@salesforce/apex/SegmentMembershipController.getSegmentMemberships';
handleSubscribe() {
// Callback invoked whenever a new event message is received
const messageCallback = function(response) {
console.log('New message received: ', JSON.stringify(response));
// Response contains the payload of the new message received
this.notifier = JSON.stringify(response);
// getSegmentMemberships({})
// .then((data) => {
// if (data) {
// console.log(data);
// this.segmentName = data[0].Segment_Name__c;
// this.segmentMembershipList = data;
// }
// })
// .catch((error) => {
// this.error = error;
// })
};
// 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;
});
Platform event -> Navigate to your Platform event -> Edit -> Publish Behavior