Newer Version Available

This content describes an older version of this product. View Latest

getAllUtilityInfo() for Lightning Experience

Returns the state of all utilities as an array of utilityInfo objects.

Arguments

None.

LWC Sample Code

Before you can use the LWC utility bar API, Lightning Web Security must be enabled.

This component returns the number of utilities in the utility bar using the utilityInfo object.

1import { LightningElement, wire } from 'lwc';
2import { getAllUtilityInfo } from 'lightning/platformUtilityBarApi';
3
4export default class UtilityInfoExample extends LightningElement {
5    utilityCount = 0;
6
7    async handleGetAllUtilityInfo() {
8        try {
9            const utilityInfo = await getAllUtilityInfo();
10            this.utilityCount = utilityInfo.length;
11
12        } catch (error) {
13            // return error
14        }
15    }
16}

To make your component available for use in a utility bar, specify the lightning__UtilityBar target in the component’s configuration file.

Aura Components Sample Code

This component has a button that, when pressed, retrieves all utilityInfo objects and opens the first utility, ordered by ID.

Component code:

1<aura:component implements="flexipage:availableForAllPageTypes" access="global" >
2    <lightning:utilityBarAPI aura:id="utilitybar" />
3    <lightning:button label="Get All Utility Info" onclick="{! c.handleGetAllUtilityInfo }" />
4</aura:component>

Controller code:

1({
2    handleGetAllUtilityInfo : function(component, event, helper) {
3        var utilityBarAPI = component.find("utilitybar");
4        utilityBarAPI.getAllUtilityInfo().then(function(response) {
5            var myUtilityInfo = response[0];
6            utilityBarAPI.openUtility({
7                utilityId: myUtilityInfo.id
8            });
9       })
10        .catch(function(error) {
11            console.log(error);
12        });
13    }
14})

Response

For both LWC and Aura Components, this method returns a promise that resolves to an array of utilityInfo objects, containing the following fields. The promise is rejected on error.

Name Type Description
id string The ID of the utility.
isLoaded boolean Whether the utility is loaded.
utilityLabel string The label of the utility.
utilityIcon string The SLDS icon ID of the utility’s icon.
utilityIconVariant string The SLDS icon variant of the utility’s icon.
utilityHighlighted boolean Whether the utility is highlighted.
utilityVisible boolean Whether the utility is visible.
utilityPoppedOut boolean Whether the utility is popped out.
panelHeaderLabel string The label of the utility panel.
panelHeaderIcon string The SLDS icon ID of the utility panel’s icon.
panelHeaderIconVariant string The SLDS icon variant of the utility panel’s icon.
panelHeight integer The height of the utility panel in pixels.
panelWidth integer The width of the utility panel in pixels