Newer Version Available

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

JavaScript Promises

Methods in the Lightning Console JavaScript API return results using promises.

This example uses the Workspace API’s openTab() function to get the tab ID of the focused tab. Then the function calls focusTab() with the tabId returned by the openTab() method.

1({
2    focusNewTab : function(component, event, helper) {
3        var workspaceAPI = component.find("workspace");
4        workspaceAPI.openTab({
5            url: '#/sObject/001R0000003HgssIAC/view',
6            label: 'Global Media'
7        }).then(function(response) {
8            workspaceAPI.focusTab({tabId : response});
9       })
10        .catch(function(error) {
11            console.log(error);
12        });
13    }
14})