Page context in the Utility Bar API

To view the page context, use a change-event handler in the Utility Bar component. If a user navigates to a different page, the recordId of the view is captured. The following code snippet shows a simple demonstration:

<aura:component implements="force:hasRecordId,flexipage:availableForAllPageTypes"access="global">    <aura:handler name="change" value="{!v.recordId}" action="{!c.onRecordIdChange}"/>    <div>            <p>The current recordId is {!v.recordId}.</p>     </div></aura:component>

The controller code for the preceding component is as follows:

({    onRecordIdChange : function(component, event, helper) {        var newRecordId = component.get("v.recordId");        console.log(newRecordId);    }})

Get Learning Salesforce Lightning Application Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.