I have a visualforce page inside my lightning Service console that displays related records of a case. On clicking on a record, I would like to open the detail in a new tab/subtab. For now, it opens in a separate window which is not in a lightning view. This is my vf page:
<apex:page showHeader="false" sidebar="false" standardController="Case" extensions="AssetRelatedListCtrl">
<apex:includeScript value="/support/console/40.0/integration.js"/>
<apex:form>
<apex:pageBlock>
<apex:selectList size="1" value="{!recordType}" style="width:130px;">
<apex:selectOptions value="{!TypeOptions}"/>
<apex:actionSupport id="recType" event="onchange" action="{!gatherRelatedAssets}" rerender="tablePanel"/>
</apex:selectList>
<apex:pageBlockTable value="{!relatedAssets}" var="asset" id="tablePanel">
<apex:column headerValue="Id">
<A HREF="#" onClick="openAssetSubtab('{!asset.Id}', '{!asset.Name}');return false">{!asset.Name}</A>
</apex:column>
<apex:column headerValue="Model" value="{!asset.Model__c}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
<script type="text/javascript">
var recordId = '{!caseId}';
var assetId;
var assetName;
function openAssetSubtab(arg1, arg2) {
assetId = arg1;
assetName = arg2;
if (sforce.console.isInConsole()) {
sforce.console.getEnclosingPrimaryTabId(openSubtab);
}else{
OpenInNewTabWinBrowser('/'+assetId);
//here, since im only using this page in the classic console and lightning console, I want to open the link in one or the other!
}
}
function OpenInNewTabWinBrowser(url) {
var win = window.open(url, '_blank');
win.focus();
}
var openSubtab = function openSubtab(result) {
var primaryTabId = result.id;
sforce.console.openSubtab(primaryTabId , '/'+assetId, true,
assetName, null, openSuccess, 'salesforceSubtab');
};
var openSuccess = function openSuccess(result) {
if (result.success == true) {
console.log('subtab successfully opened');
} else {
console.log('subtab cannot be opened');
}
};
</script>
Best Answer
You can use
sforce.one.navigateToSObject('{!asset.Id}')
which will open a record in new lightning console tab.