// -------
({
openUtilityBar : function(component, event, helper) {
var utilityAPI = component.find("utilitybar");
utilityAPI.openUtility();
}
openTab : function(component, event, helper) {
var workspaceAPI = component.find("workspace");
workspaceAPI.openTab({
url: ‘#/sObject/001R0000003HgssIAC/view’,
focus: true
}).then(function(response) {
workspaceAPI.getTabInfo({
tabId: response
}).then(function(tabInfo) {
console.log(“The recordId for this tab is: “ + tabInfo.recordId);
});
})
.catch(function(error) {
console.log(error);
});
}
})
// Methods in the Lightning Console JavaScript API return results using promises
({
focusNewTab : function(component, event, helper) {
var workspaceAPI = component.find("workspace");
// get the tab ID of the focused tab
workspaceAPI.openTab({
url: '#/sObject/001R0000003HgssIAC/view',
label: 'Global Media'
}).then(function(response) {
// respsone from the promise
// Promises can simplify code that handles
// the success or failure of asynchronous calls
workspaceAPI.focusTab({tabId : response});
})
.catch(function(error) {
// Promises can simplify code that
// handles the success or failure of asynchronous calls
/*
The catch() method returns a promise and
accepts a single function parameter that’s called if the promise is rejected.
This function has one argument that shows the reason for the rejection.
The promise returned by catch() is rejected if the function that is passed
in either throws an error or returns a promise that’s rejected.
Otherwise, the promise is resolved.
*/
console.log(error);
});
}
})
// implements force:hasRecordId and listens for changes to the record being viewed
// When this component is added to a utility bar,
// it displays the recordId of the record currently being viewed.
The current recordId is {!v.recordId}.
// controller
({
onRecordIdChange : function(component, event, helper) {
var newRecordId = component.get("v.recordId");
console.log(newRecordId);
}
})
// component - has a button that, when pressed, opens a tab and sets the tab’s icon to the SLDS emoji icon.
({ // controller
openTab : function(component, event, helper) {
var workspace = component.find("workspace");
workspace.openTab({
url: '/sObject/001R0000003HgssIAC/view',
focus: true,
callback : function(error, response) {
workspace.focusTab({tabId : response });
}
});
}
})
// component - has a button that, when pressed, opens a tab.
({ // controller
setFocusedTabIcon : function(component, event, helper) {
var workspace = component.find("workspace");
workspace.getFocusedTabInfo({
callback : function(error, response) {
var focusedTabId = response.tabId;
workspace.setTabIcon({tabId : focusedTabId, icon: 'like', iconAlt: 'like' });
}
});
}
})
// Use events and handlers in your Lightning components and controllers
// to respond to events like workspace tabs opening, closing, or
// gaining focus.
// prints a line to the browser’s developer console
// when a tab is closed
// component
// controller
({
onTabclosed : function(component, event, helper) {
console.log("Tab closed.");
},
})