I have a managed package that contains a legacy web tab that now needs some more advanced logic to be added to the destination. This all but requires the tab to now point to a visualforce page.

However the problem is that we have a large number of dev and test orgs with unmanaged copies of our code, and hardcoding the namespace prefix in the web tab link would break in these.

I've already tested and the $Page and $Resource globals appear to be unavailable inside the limited merge field capabilities of web tabs.

$ObjectType appears to be available, but so far seems incapable of returning anything but a sObject's key prefix ($ObjectType.Account.fields.name fails to save, while $ObjectType.Account returns the text 001).

What options do I have left for detecting if this org is running an unmanaged or managed copy of the app?

  • Untested, so not an answer, but is the web tab's target document (in the iframe) able to query parent.location.href via JS? If so, perhaps that URL contains enough info to get you what you need and do a redirect after the initial request? – jkraybill Feb 12 '13 at 3:55
  • Not sure that will help. If I link to /apex/namespace__page it will fail to resolve in dev orgs and if I do /apex/page it won't resolve in the packaged version - so I can't rely on JS on the target page for this. – ca_peterson Feb 12 '13 at 19:26

You are out of luck with button code and web tabs, both of which require explicit namespace prefixing. Our solution was to keep all dev, and the canonical master branch, not bound to the managed package instance. In other words, your primary stable release code lives in a dev instance called your staging server or something. You can have lots of other dev instances for your team and the canonical copy of your web tab and buttons does not have a namespace prefix.

Ideally, you would setup Jenkins or some other scripting tool to deploy every checked in change from Github or wherever you're hosting you VCS, to your managed instance, transforming the button code and web tabs in the script, running tests in your managed instance and spitting back the results to you. If you create this, every Salesforce ISV with a team of more than one person will want it.

| improve this answer | |
  • 2
    You'd think salesforce would notice the cries of pain on every single ISV and give us a CURRENTNAMESPACE() function for formulas or something. – ca_peterson Feb 13 '13 at 0:24

From your description, I strongly suspect that the solution to your problem would be the URLFOR function. You'd be able to use it to dynamically pass any values from inside your web tab to a target destination. It's use is explained in fairly good detail in a blog at the following url: http://ravindrasinghbist.blogspot.com/2011/05/urlfor-function-finally-explained.html. Pretty much anything available to the web tab could easily be passed to another page using that function.

| improve this answer | |
  • 1
    Sadly the $Resource and $Page variables don't work in web tab formulas. I'm not sure what I could pass to URLFOR that properly handles a namespace at runtime. – ca_peterson Feb 13 '13 at 0:22

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.