3

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. enter image description here

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>

0

1 Answer 1

1

To recognize whether the page is in console or classic view (non-console) change the formula field like this:

Formula field to open visualforce in console

HYPERLINK("javascript:if(typeof(srcUp)=='function') {srcSelf('/apex/Sitepage?id=" & Id & "');} "+ 
" else {window.location.href='/" & Id & "'}" 
,Name 
, "_Parent" 
)

The typeof(srcUp)=='function' identifies if page is in console.

Also, expanding this answer to help other community members.

Formula field to open Standard Record Detail page in console

HYPERLINK("javascript:if(typeof(srcUp)=='function') {srcUp('/" & Id & "?isdtp=vw');} "+
" else {window.location.href='/" & Id & "'}"
,Name, 
"_parent"
)

srcUp is a method that allows us to open new subtabs when in the Salesforce.com domain.

srcSelf is just like the srcUp method. The only difference is that instead of opening a new subtab, it navigates the current tab to the target url

isdtp=vw in the target link helps to render the page correctly in console.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .