I am trying to navigate to a VF page on click of a (Formula field) field from list view.
Now my requirement is to navigate to standard detail page of Site record when clicked from standard list view (non console app/custom app) or else to a custom VF page if clicked from Console list view.
Issue: Unable to differentiate whether the page is opened from Console or custom App(standard view).For this I have used isInConsole() method but it always returns false i.e., even when the page is opened in console (by clicking the formula field on list view) .
Can you please guide me on how to resolve this issue?
Formula Field Definition :
HYPERLINK("https://c.cs26.visual.force.com/apex/SItepage?id=" & Id, Name,'_self')
Page Code:
<script type="text/javascript">
//Onload function to call JS methods
window.onload = function Redirect() {
testIsInConsole();
testOpenPrimaryTab();
}
//isInConsole method to check the whether VF page is opened in Console/classic(standard)
function testIsInConsole() {
if (sforce.console.isInConsole()) {
alert('in console');
} else {
alert('not in console');
}
}
function testOpenPrimaryTab() {
var siteid = '{!siteid}';
var Sitename = '{!Site__c.name}';
var Arltcount = '{!Alertcount}';
var Alertscheck = '{!Alertverified}';
//if parent contains any childs records then navigate to VF page
if (Arltcount > 0 && Alertscheck == 'false') {
sforce.console.openPrimaryTab(null, '/apex/SiteAlertPage?id=' +
siteid, true, Sitename, openSuccess, 'salesforceTab');
}
//if parent does not contain any childs records then navigate standard Detail page
else {
sforce.console.openPrimaryTab(null, '/' + siteid, true, Sitename, openSuccess, 'salesforceTab');
}
}
</script>