Skip to content

Instantly share code, notes, and snippets.

@justin-lyon
Created October 25, 2019 14:43
Show Gist options
  • Save justin-lyon/c0a2f2cd44238e5d36bf73c0d25f3567 to your computer and use it in GitHub Desktop.
Save justin-lyon/c0a2f2cd44238e5d36bf73c0d25f3567 to your computer and use it in GitHub Desktop.
lightning:utilityBarAPI testing
<aura:component description="NewCaseUtilityItem"
implements="lightning:utilityItem, force:hasRecordId"
access="global">
<lightning:utilityBarAPI aura:id="utilityBar" />
<aura:attribute name="utilityItemId" type="String" default="" />
<aura:attribute name="isActive" type="Boolean" default="false" />
<aura:attribute name="activeRecordId" type="Id" default="" />
<aura:handler name="init" value="{!this}" action="{!c.init}" />
<aura:handler name="change" value="{!v.recordId}" action="{!c.onRecordChange}" />
<c:myComponent recordId="{!v.recordId}" />
<lightning:button
label="Cancel"
onclick="{!c.onCancel}"></lightning:button>
</aura:component>
({
init: function(cmp, event, helper) {
var eventHandler = function() {
helper.getUtilityInfos(cmp);
};
var utilityBar = cmp.find('utilityBar');
utilityBar.onUtilityClick({eventHandler}); // -> Error: Invalid or missing utilityId `false`
/*
This component is configured as a Utility Bar Item in my Console App.
The component is configured to initialize after it is opened.
Documentation states that utilityId is an optional argument if called from within a Utility Item component.
https://developer.salesforce.com/docs/atlas.en-us.api_console.meta/api_console/sforce_api_console_lightning_getUtilityInfo.htm
I am getting errors on all utility bar api methods that accept this optional utilityId argument, and I can't fathom why.
*/
},
onRecordChange: function(cmp, event, helper) {
var newRecordId = cmp.get("v.recordId");
console.log('newRecordId', newRecordId);
},
onCancel: function(cmp, event, helper) {
console.log('canceling');
}
})
({
getUtilityInfos: function(cmp) {
var utilityBar = cmp.find('utilityBar');
utilityBar.getAllUtilityInfo()
.then(res => {
console.log('getAllUtilityInfo', JSON.parse(JSON.stringify(res)));
})
.catch(err => {
console.error('error getAllUtilityInfo', err);
})
utilityBar.getUtilityInfo()
.then(res => {
console.log('getUtilityInfo', JSON.parse(JSON.stringify(res)));
})
.catch(err => {
console.error('error getUtilityInfo', err);
})
utilityBar.getEnclosingUtilityId()
.then(res => {
console.log('getEnclosingUtilityId', JSON.parse(JSON.stringify(res)));
})
.catch(err => {
console.error('error getEnclosingUtilityId', err);
})
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment