You need to sign in to do that
Don't have an account?
DML2020
How to reference recordId in controller of aura component?
A custom aura component is embedded in the screen element of a screen flow with the purpose of closing and opening specific tabs on the UI. The id of the tab to open in this case is defined as 'tabIdToOpen'.
From the code below, how should the markup appear for / what is the correct way to reference the recordId for the 'tabIdToOpen' in the controller file (line 7after recordId:)?
Component code 🔻
<aura:component implements="lightning:availableForFlowScreens"> <aura:attribute name="tabIdToOpen" type="string" /> <lightning:workspaceAPI aura:id="workspace" /> <aura:handler name="init" value="{!this}" action="{!c.closeCurrentTab}" /> </aura:component>
Controller code 🔻
({ closeCurrentTab : function(component, event, helper) { var workspaceAPI = component.find("workspace"); workspaceAPI.getFocusedTabInfo().then(function(response) { var focusedTabId = response.tabId; workspaceAPI.openTab({ recordId: tabIdToOpen, focus: true }).then(function(response) { workspaceAPI.closeTab({tabId: focusedTabId}); }) .catch(function(error) { console.log(error); }); }); } })Design Code
<design:component > <design:attribute name="tabIdToOpen" label="Id of tab to open" /> </design:component>Reference -> openTab() for Lightning Experience (https://developer.salesforce.com/docs/atlas.en-us.api_console.meta/api_console/sforce_api_console_lightning_opentab.htm) sample code
To reference the tabIdToOpen attribute in the controller file, you need to use the component.get() method. Here's the modified controller code: In the modified code, component.get("v.tabIdToOpen") is used to retrieve the value of the tabIdToOpen attribute in the controller.
Make sure the markup for the component includes the attribute binding for tabIdToOpen. Here's an example: The design code you provided is already correct for defining the design attribute.
If this helps , please mark this as Best Answer.
Thank you.
Thanks for the speedy reply, Subrat!
That component.get() method is key. Alternatively, I included it in my controller code as below (line 7) and it satisfied the requirement:
🔴 Follow-up question: How is the example markup for the component above, to include the attribute binding for tabIdToOpen, different than what I originally posted?