Skip to content

Commit

Permalink
subscribe to platform event for refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Jul 1, 2020
1 parent e2f6288 commit 9cd5f2e
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { loadStyle } from 'lightning/platformResourceLoader';
import mapModal from '@salesforce/resourceUrl/mapModal';
import { subscribe, unsubscribe } from 'lightning/empApi';

import getRecs from '@salesforce/apex/getRecommendations.getRecommendations';
import getRecommendations from '@salesforce/apex/getRecommendations.getRecommendations';

const eventChannel = '/event/Client_Profile_Update_Notification__e';

Expand Down Expand Up @@ -54,7 +54,7 @@ export default class ServiceRecommendations extends LightningElement {
handleRequestRecommendations() {
console.log('getting recommendations');
console.log('recorid Id' + this.recordId);
getRecs({ contactId: '003J000001uUczOIAS' })
getRecommendations({ contactId: this.recordId })
.then((result) => {
window.console.log('success');
if (this.showRecommendations === false) {
Expand All @@ -64,7 +64,8 @@ export default class ServiceRecommendations extends LightningElement {
this.returnRecommendations = result;
})
.catch((error) => {
window.console.log('error:' + error);
// window.console.log('error:' + error);
console.log(JSON.parse(JSON.stringify(error)));
});
}

Expand Down Expand Up @@ -149,10 +150,12 @@ export default class ServiceRecommendations extends LightningElement {
}

handleSubscribe() {
const messageCallback = (response) => {
console.log(response);
if (response.data.payload.ContactId === this.recordId) {
this.handleRequestRecommendations();
const context = this;
const messageCallback = function (response) {
console.log(JSON.stringify(response));
console.log(context.recordId);
if (response.data.payload.ContactId__c === context.recordId) {
context.handleRequestRecommendations();
}
};
subscribe(eventChannel, -1, messageCallback).then((response) => {
Expand All @@ -167,6 +170,7 @@ export default class ServiceRecommendations extends LightningElement {

renderedCallback() {
this.handleSubscribe();
console.log('version 9');
}

disconnectedCallback() {
Expand Down

0 comments on commit 9cd5f2e

Please sign in to comment.