I have a lightning component that displays a message on the Opportunity record detail page. This message displays based on criteria on the Opportunity which references a rollup field that provides a count of related records. If the count is zero, the component displays the message. If the count is greater than zero the message does not display. All of this works fine except when deleting the related record from the related list on the Opportunity. If the record is deleted and the count drops to zero, the message does not automatically display unless the Opportunity record is refreshed.

I tried using:


Here is my component code:

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" >
    <aura:handler name="init" value="{!this}" action="{!c.init}"/> 
    <div class="slds-notify slds-box slds-theme_error">
        <div class="slds-notify__content">
            <h2 class="slds-text-heading_small slds-align_absolute-center">Message Title Here!!</h2>
            <p class="slds-align_absolute-center">Message body goes here...</p>                

here is the controller:

    init : function(component, event, helper) {

I need the component to display correctly when the related records are added/modified/deleted from the related list on the Opportunity record without having to manually refresh the Opportunity detail page.

1 Answer 1


this is because the related list is a totally different component and your custom component is not wired to refresh based on field value. If showing the component is dependent on a field value, you could use a process builder to fire a Platform event then on your component, then use a lightning:emApi which listens to the PE fired when count drops to zero. But this is only supported in desktop for now.


put this on the component markup:

<lightning:empApi aura:id="empApi"/>
<lightning:input aura:id="channel" label="channel" name="channel" type="text" value="/event/SamplePE__e"/>
    // Sets an empApi error handler on component initialization
    onInit : function(component, event, helper) {

        // Get the empApi component
        const empApi = component.find('empApi');
        // Get the channel from the input box
        const channel = component.find('channel').get('v.value');
        // Replay option to get new events
        const replayId = -1;

        // Subscribe to an event
        empApi.subscribe(channel, replayId, $A.getCallback(eventReceived => {
         // TODO: show your component here. either use aura:if or use modal css slds-show or slds-hide to toggle you component.
        .then(subscription => {
            // Confirmed that we have subscribed to the event channel
            // you can save the subscription if you want to unsubscribe later. e.g. once it reaches zero, totally unsubscribe. But if the value will still change, no need to unsubscribe since your component should still listen to it

        // Register error listener and pass in the error handler function
        empApi.onError($A.getCallback(error => {
            console.error('EMP API error: ', error);


You must log in to answer this question.

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