0

I need to update this hardcoded url before an instance refresh and I am having difficulties finding a solution.

The VF page is from a managed package that has the namespace of scl

I have tried to use the URLFOR function with the $Page Global Variable but it errors on the $Page. reference

var url = '{!URLFOR($Page.scl_Simple_Comment_List, null, [Id=Case.Id])}';

Here is the onclick javascript that is in the button today that I need to change so it no longer has a hardcoded reference to the instance

{!REQUIRESCRIPT("/support/console/30.0/integration.js")} 

var url = 'https://scl.na28.visual.force.com/apex/Simple_Comment_List?Id={!Case.Id}'; 

if (sforce.console.isInConsole()) { 
// Use the results primary tab id and open a new subtab 
var openSubtab = function(result){ 
sforce.console.openSubtab(result.id, url, true, 'Case Comments', null); 
}; 
sforce.console.getEnclosingPrimaryTabId(openSubtab); 
} else { 
window.open(url,'_blank'); 
}
  • Make sure you add the package namespace. – itzmukeshy7 Jun 30 '17 at 22:10
  • @itzmukeshy7 I tried it via the URLFOR and $Page. scl at the beginning of the page name is the namespace – Jason Jun 30 '17 at 22:15
  • My prior answer was actually incorrect, so I deleted it and replaced it with a new version that should do what you want it to do. – sfdcfox Jul 2 '17 at 3:05
2

Your code doesn't need the server name, $Page, or URLFOR; both your browser and the Service Console accepts relative URLs, so this code should work:

{!REQUIRESCRIPT("/support/console/30.0/integration.js")} 
var url = '/apex/scl__Simple_Comment_List?Id={!Case.Id}'; 

if (sforce.console.isInConsole()) { 
  // Use the results primary tab id and open a new subtab 
  sforce.console.getEnclosingPrimaryTabId(function(result){ 
    sforce.console.openSubtab(result.id, url, true, 'Case Comments', null); 
  }); 
} else { 
  window.open(url,'_blank'); 
}

When you use /apex/namespace__pagename, Salesforce automatically redirects to the correct namespaced URL (e.g. scl.na28.visual.force.com).

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.