I am using lighting empApi to refresh the component whenever a case record is created. I have a trigger & apex class in case object that fires and update the platform event object.

In Detail-record page, where you can see Tracking component(one of the components in Detail-record page) whenever a new case is created it's retrieving the new data into tracking component, for that I am using lightning:empApi concept using platform event I capturing the live record without a manual refresh.

Now my issue is this auto refresh is working for all the records in the same object instead of one I am working on.

So far I am thinking that, after inserting the case record, the component reloads using empApi and calling the subscribe method. that time it's not checking with the recordId.

and also I am using show spinner in the components if the data is loading. So, I am not sure if this is the reason for the issue.

Please ask me if you have any question

  <aura:component controller="ClassController"

   <aura:attribute name="recordId" 
                type="Id" />

  <aura:handler name="sub"  value="{!this}" action="{!c.Subcribe}" />

<lightning:empApi aura:id="empApi"/>

          <aura:if isTrue="{!v.showSpinner}">
                    <lightning:spinner alternativeText="Loading" size="small"/>
        //// code


    var empApi = component.find('empApi')
    var replayId = -1
    var channel = component.get('v.channel')
    helper.getHelperfunction(component, event, helper)

    var sub = function(message){

        helper.getHelperfunction(component, event, helper)

      empApi.subscribe(channel, replayId, sub)

Helper class

        getHelperfunction: function(component,event,helper) {
        var action = component.get('c.getListOfCases');
        if(response.getState() === "SUCCESS"){



   trigger Cases on Case (after insert) {
if(Trigger.isAfter) {
    // Send the list of cases (Trigger.new) to the example function


class for fire from trigger

      public class ExampleClass {
      public static void publishCaseUpdateNotifications(List<Case> cases) {
      List<Case_Upd__e> notifications = new List<Case_Upd__e>();
      for (Case c: cases) {
        notifications.add(new Case_Upd__e(
            CaseNumber__c = c.CaseNumber

    List<Database.SaveResult> results = EventBus.publish(notifications);
  • What does gHelperfunction() do?
    – David Reed
    Jun 23, 2019 at 0:01
  • I have an added gHelperfunction () code, simply get the callback function for subscribe method. Jun 23, 2019 at 12:06

1 Answer 1


Your code is performing lots of unnecessary server trips and refreshes because it doesn't

  1. Provide enough detail in the Platform Event, as fired by the trigger, for each subscriber to determine if the event is relevant to what it is displaying. Based on what I recall of your previous questions, that would probably be a parent record Id.
  2. Evaluate the Platform Event details in the JavaScript callback method to determine if it needs to perform a refresh at all - i.e., whether the event it's receiving actually affects the data it is displaying.

If you fix that issue, you may even obviate the need to perform a server round trip at all. Including more details in the Platform Event might allow your consumer to query the server only once, and thereafter update purely via events. Be aware, however, that adopting such an architecture does open up a race condition that you'll need to be ready to handle.

Lastly, calling your Platform Event Low_Ink__e, as copied and pasted directly from the documentation, is going to be confusing. You should name it something that reflects what it actually does.

  • How to Evaluate the Platform Event details in the JavaScript callback method. using this document lightning:empApi/documentation I can fetch the platform event using $A.getCallback but how to evaluate the platform event details into Js helperController. Jun 24, 2019 at 12:46
  • @StephenRoy Your function sub() throws away the message that the empApi component is providing. You would need to pass the message to your handler function and inspect the values in the message there.
    – David Reed
    Jun 24, 2019 at 12:48
  • If possible could you please provide any example how to pass the message to handler function. Jun 24, 2019 at 13:05
  • Stephen, I'm just saying that you need to pass the parameter you're already receiving to another function. Then, write code to check the values in the message you receive based on the changes you make to your Platform Event, as I suggest above. I don't have any prewritten examples that apply to that use case.
    – David Reed
    Jun 24, 2019 at 13:06
  • empApi.subscribe(channel, replayId, sub).then(function(newSubscription){ component.set('v.subscribeview', newSubscription) you meant like this. Jun 24, 2019 at 13:37

You must log in to answer this question.

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