1

I want to redirect user to a VF Page from a managed Package UI where code is written in Angular JS,

<div class="slds-no-flex">
    <span><button class="slds-button slds-button" onclick="redirectToMap();" id="Btn" value="{{a.id}}">View Map</button></span>

JS

 function redirectToMap() {

sforce.console.getEnclosingPrimaryTabId(openSubtab);
sforce.console.getFocusedSubtabId(closeSubtab);


}

var closeSubtab = function closeSubtab(result) {

var tabId = result.id;
sforce.console.closeTab(tabId);

  };

var openSubtab = function openSubtab(result) {

var parentID = document.getElementById("Btn").value;
var primaryTabId = result.id;
sforce.console.openSubtab(primaryTabId ,'/apex/AccountDisplayVF?id=' + parentID, 
true, 'New Map', null);
};

This isn't working . Anything I am missing?

  • 3
    have you tried '/apex/c__AccountDisplayVF' (assuming that page is unmanaged)? – Phil Hawthorn Jun 13 '17 at 17:14
  • 1
    Are you in the console UI? The code you posted looks like it would only work there. – Daniel Hoechst Jun 13 '17 at 17:47
  • I'll write up a brief answer for posterity – Phil Hawthorn Jun 14 '17 at 17:18
2

The issue here is that when you're opening an unmanaged page from a Managed package, the platform is assuming the namespace of the managed package should also prefix your Visualforce page.

So, for example, if you have a Visualforce page in the NS namespace, and then put a button on that page that navigates to an unmanaged page, the platform would assume that you wanted NS__MyPage instead of just MyPage. To prevent this, you can qualify your Page with the local (c) namespace, so in your case:

/apex/c__AccountDisplayVF
|improve this answer|||||
4

Always use $Page global variable for redirection in a visualforce page.

$Page.PageName if its outside namespace.

or $Page.Namespace__PageName, if its inside.


For accessing $Page in JavaScript placed inside a static resource, use:

  1. a global variable

  2. some design pattern to avoid a global variable as mention in this blog.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.