2

We're working on a Salesforce managed package that contains visualforce pages that are to be published on a Salesforce site.

When testing, we can access those pages at http://example.force.com/pagename

But when installing the managed package on a testing org, we can only access those pages is prepending the package namespace, http://example.force.com/namespace__pagename

How can I make the pages accessible at /pagename even when accessing from a managed package instalation?

  • 1
    How do you reference the page? If it's from Apex code that's also in the package, make sure you don't hard-code the page name, but use new Page.PageName. If you do it from javascript, you could include the namespace prefix in the page name, as that will also work on your packaging org. You will be in a bit of trouble if you actually develop on a separate dev org. In that case you could create a function to get the namespace prefix and put it in a custom setting or custom metadata object. – rael_kid Dec 14 '15 at 8:48
  • @Lex Yes.. It was hard-code th page name and with Page.PageName work good... I think... Thank you – Hungry Dec 14 '15 at 12:22
0

Like I said in my comment; this depends on how the page is referenced. If it's done from Apex code within the package itself, make sure to use PageReference pr = Page.PageName; in favor of PageReference pr = new PageRefence('/apex/PageName'); The former automatically takes the namespace prefix into account.

If it's done from JavaScript however, it could get a little more complex. JS doesn't know anything about the namespace prefix, so you'd have to create an Apex function that returns the prefix and call that from JS to determine how you should set up your links. This question has some interesting stuff about how to get the namespace in JS.

To answer the question asked in the comments: If you have the name of the page (without the namespace prefix) and want to get a PageReference dynamically, you can use the ApexPage sObject. Like so:

String pageName = 'MyPage';
ApexPage[] aps = [SELECT Id, NamespacePrefix, Name FROM ApexPage WHERE Name = :pageName];
String pageUrl = aps[0].NamespacePrefix != null ? aps[0].NamespacePrefix + '__' : '';
pageUrl += aps[0].Name;
PageReference pr = new PageReference(pageUrl);

Note that the query will return all pages with the same name, also ones with a different namespace prefix. So you should always make sure that the namespace prefix is one you expect.

|improve this answer|||||
  • Ty. And... Maybe you can help me with another thing. If i have String variable with name of a page, how use Page.PageName? – Hungry Dec 15 '15 at 7:08
  • I've updated my answer. – rael_kid Dec 15 '15 at 8:31
0

Have a look at the URLRewritter which may do what you need. I haven't tried it with removing managed package namespace in the url but works well in other cases.

|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.