function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mathieu Perrin 13Mathieu Perrin 13 

Page Context in Background Utility Item

I created a Background Utility Item component that uses empApi component to listen on capture data change. I need to have it aware of Page Context and able to get record id of current page. I tried to use force:hasRecordId interface with component.get("v.recordId") but it doesn't works. If I remove the lightning:backgroundUtilityItem interface and use it in Utility Bar, I am able to retrieve the record id. Do you know if it is by design or an issue from Salesforce ? Do you have any workaround ?
Thank you
<aura:component implements="flexipage:availableForAllPageTypes,lightning:backgroundUtilityItem,force:hasRecordId" access="global">
	<aura:attribute name="channel" type="String" required="true" default="/data/ChangeEvents" />
	<aura:attribute name="checkRecordId" type="Boolean" default="true" />
	<aura:attribute name="debug" type="Boolean" default="false" />
	<aura:handler name="SubscribeStreamingChannelEvent" event="c:SubscribeStreamingChannelEvent" action="{!c.handleSubscribeEvent}"/>
	<aura:handler name="destroy" value="{!this}" action="{!c.unsubscribe}"/>
	<c:StreamingChannelSubscriber channel="{!}" debug="{!v.debug}" />
	handleSubscribeEvent : function(component, event, helper) {
		const debug = component.get("v.debug");
		const message = event.getParam('recordData');
        const eventType = message.payload.ChangeEventHeader.changeType;
        const entityName = message.payload.ChangeEventHeader.entityName;
        const userId = message.payload.ChangeEventHeader.commitUser.substring(0, 15); //15 digit id of transaction commit user
        const signedInUser= $A.get("$SObjectType.CurrentUser.Id").substring(0, 15); //15 digit id of logged in user
		const checkRecordId = component.get("v.checkRecordId");
         * Conditions:
         * - Change Type should not be create
         * - Record Id must present in modified recordIds
         * - User who modified the record should not be logged in user
         * */
        if(!(eventType === "CREATE")){
            //Condition 1 - Change type is not "created"
            Array.from(message.payload.ChangeEventHeader.recordIds).forEach( recordId => {
				if(debug && checkRecordId) console.log("Record Id on page = " + component.get("v.recordId") + " - Record Id in event = " + recordId);
                if(!checkRecordId || (checkRecordId && recordId === component.get("v.recordId"))){
                    //Condition 2 - Record Id match found &&
                    //Condition 3 - commit user is not logged in user
                    //Display console log with changed values
					if(debug) console.log(`${eventType} event captured on ${entityName} by user id ${userId}`);
                    if(debug) console.log("Values changed are:");