public class ObjectService {
@AuraEnabled
public static String getObjectType(String objectId) {
Id conId = objectId;
return String.valueOf(conId.getSobjectType());
}
}
执行以下步骤创建 lightning 组件:
选择文件>新建>Lightning 组件。
指定组件名称。 例如,CopilotForService。
从创建组件时显示的捆绑面板中选择控制器,然后粘贴以下代码:
({
onTabFocused : function(component, event, helper) {
var currentTabId = event.getParam('currentTabId');
var previousTabId = event.getParam('previousTabId');
var workspaceAPI = component.find("workspace");
if(currentTabId) {
workspaceAPI.getTabInfo({
tabId : currentTabId
}).then(function(response) {
var action = component.get("c.getObjectType");
var recordId = response.recordId;
action.setParams({"objectId": recordId});
action.setCallback(this, function(response) {
var state = response.getState();
if(state === "SUCCESS") {
component.set("v.objectType",response.getReturnValue());
var type = response.getReturnValue();
console.log("Object details:", recordId, type);
var objectType = 0;
if (type == 'Case') {
objectType = 1;
} else if (type == 'EmailMessage') {
objectType = 2;
} else if (type == "LiveChatTranscript") {
objectType = 8;
}
console.log("iframe: ", document.querySelector('iframe.CFSLightning'));
// Invoke adapter to navigate based on objectid and objecttype
document.querySelector('iframe.CFSLightning').contentWindow.postMessage({
messageType: "onPageNavigateFromSFLightningComponent",
messageData: JSON.stringify({
value: JSON.stringify({
objectId: recordId,
objectType: objectType,
sourceId: "b54abfa8-3d78-4aa0-ae3f-1e2ffbc56850"
})
})
}, "*");
} else {
console.log('Problem updating the case, response state: ' + state);
}
});
$A.enqueueAction(action);
});
} else {
// When user navigates to the entity list page, switch to global session
console.log("global!");
document.querySelector('iframe.CFSLightning').contentWindow.postMessage({
messageType: "onPageNavigateFromSFLightningComponent",
messageData: JSON.stringify({
value: JSON.stringify({
objectId: "",
objectType: 0,
sourceId: "b54abfa8-3d78-4aa0-ae3f-1e2ffbc56850"
})
})
}, "*");
}
}
})