Sunday 14 October 2018

lightning:workspaceAPI on Lightning Console Applications (Getting record id from record tab)

Hi ,

To access tabs or sub tabs information in Salesforce Classic console application we have Console Integration Toolkit.
In the same way to access tabs or sub tabs information in Lightning Conosle Application we have to use "workspaceAPI".
To access methods of "workspaceAPI" we have to create an instance of the lightning:workspaceAPI component and assign an aura:id attribute to it as shown below .

<lightning:workspaceAPI aura:id="workspace"/>

This component allows you to access methods for programmatically controlling workspace tabs and subtabs in a Lightning console app. In Lightning console apps, records open as workspace tabs and their related records open as subtabs.

Scenario:
When a record is opened in Lighning Console application  we should be able to find out the record ID from the record tab, for further process from application utility menu items.

Eg:


<aura:component                  implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,force:appHostable" 
                access="global"  controller="UpdateCaseController">
    <lightning:workspaceAPI aura:id="workspace" />

    <aura:attribute name="recordId" type="String"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
</aura:component>


JSController:

({
doInit : function(component, event, helper) {
        
        var workspaceAPI = component.find("workspace");
        workspaceAPI.getTabInfo().then(function(response) {
                       var action = component.get("c.updateCase");        
                       action.setParams({"caseRecordId":response.recordId});
                       action.setCallback(this,function(data){
                             var result = data.getReturnValue();
                              
                     });
                    $A.enqueueAction(action);
        });
})

Apex Controller:

public class UpdateCaseController{
  @Auraenabled
   public static void updateCase(String caseRecordId){
       Case caseObj = new Case(Id=caseRecordId,ownerId=UserInfo.getUserId());
        update caseObj;
   }
   

}


Reference:

https://developer.salesforce.com/docs/component-library/bundle/lightning:workspaceAPI/documentation

https://developer.salesforce.com/docs/atlas.en-us.api_console.meta/api_console/sforce_api_console_methods_lightning_tabs.htm





1 comment:

How to include a screen flow in a Lightning Web Component

 Hi, Assume  you have a flow called "Quick Contact Creation" and API Name for the same is "Quick_Contact_Creation". To i...