8

I am using platform event and subscribing them in a lightning component. When i use my component as standalone lightning app or use it on lightning record page, the components subscribe well to the event.

// Client-side function that invokes the subscribe method on the empApi component.
subscribe: function (component, event, helper) {
    // Get the empApi component.
    console.log('calling to subscribe');
    debugger;
    var empApi = component.find('empApi');
    // Get the channel from the attribute.
    var channel = component.get('v.channel');
    // Subscription option to get only new events.
    var replayId = -1;
    // Callback function to be passed in the subscribe call.
    // After an event is received, this callback prints the event
    // payload to the console. A helper method displays the message
    // in the console app.
    var subscribeCallback = function (message) {
        console.log('Event Received : ' + JSON.stringify(message));
        helper.onReceiveNotification(component, message);
    };
    // Subscribe to the channel and save the returned subscription object.
    empApi.subscribe(channel, replayId, subscribeCallback).then($A.getCallback(function (newSubscription) {
        console.log('Subscribed to channel ' + channel);
        component.set('v.subscription', newSubscription);
    }));

    /*.catch(
        function(error) {
            console.error('cant subscribe to event ', JSON.stringify(error));
        }
    );*/
},

In the subscribe method - there is a console log - Subscribed to channel.

empApi.subscribe(channel, replayId, subscribeCallback).then($A.getCallback(function (newSubscription) {
    console.log('Subscribed to channel ' + channel);
    component.set('v.subscription', newSubscription);
}));

It works fine for above mentioned scenarios and gets called well from Init.

If i put the component on the community page, the component stops subscribing and 'Subscribed to channel' does not show.

2
  • Is there an alternative? A way to subscribe to PE on a community page?
    – Julian
    Commented May 26, 2019 at 23:31
  • Nope! haven't found it yet! If i see console logs, i see that the component will subscribe to events in community but will not get any notifications! Don't know if things have changed! Commented May 27, 2019 at 9:02

1 Answer 1

11

Per documentation, lightning:empApi is not supported in Communities. If you refer to the Experience section in the documentation, the only supported experiences are LEX and Mobile.

Refer screenshot from the documentation:

enter image description here

1
  • 2
    As of Winter'21 (21/10/2020) per the updated documentation, developer.salesforce.com/docs/component-library/bundle/… the Salesforce Mobile App is removed and only Lightning Experience is supported Commented Oct 21, 2020 at 12:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .