Records in Salesforce service console takes standard name or casenumber as default tab name.
To override the default tab name , we can leverage console javascript tool kit by using getFocusedTabInfo() to rename the tab.
For that we need to create a lightning component and add it to the lightning page of record in service console by editing the page (Edit Page).
Here is the code of the lightning component.
RenameTab.cmp (Component file)
<aura:component controller="TabLabel" implements="flexipage:availableForAllPageTypes" access="global" >
<lightning:workspaceAPI aura:id="workspace" />
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<aura:attribute name="case" type="Case" />
</aura:component>
RenameTabContoller.js (Controller file)
({
doInit : function(component, event, helper) {
helper.addDelay(component, event, helper);
}
})
RenameTabHelper.js (Helper file)
({
addDelay : function(component,event,helper) {
var i = 0;
var interval = window.setInterval(
$A.getCallback(function() {
var cs = component.get("v.case") ;
if (!component.isValid() || (i === 10)){
window.clearInterval(interval);
return;
}
helper.setFocusedTabLabel(component, event, helper);
i++;
}), 100
);
},
setFocusedTabLabel : function(component, event, helper) {
var workspaceAPI = component.find("workspace");
workspaceAPI.getFocusedTabInfo().then(function(response) {
var focusedTabId = response.tabId;
var recordId = response.recordId ;
var action = component.get("c.getCase");
action.setStorable();
action.setParams({"caseId": recordId});
// Configure response handler
action.setCallback(this, function(response) {
var state = response.getState();
if(component.isValid() && state === "SUCCESS") {
component.set("v.case", response.getReturnValue());
} else {
console.log('Problem getting case, response state: ' + state);
}
});
$A.enqueueAction(action);
var caseObj = component.get("v.case") ;
if(caseObj !=null){
workspaceAPI.setTabLabel({
tabId: focusedTabId,
label: caseObj .casenumber
});
}
})
.catch(function(error) {
console.log(error);
});
}
})
TabLabel.cls (Controller class)
@AuraEnabled
public static Case getCase(Id caseId) {
// Perform isAccessible() checks here
if (Schema.sObjectType.Case.fields.casenumber.isAccessible() ) {
return [SELECT id , casenumber FROM case WHERE Id = :caseId];
}else{
return null;
}
}
}
Comments
Post a Comment