function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
umutdoganumutdogan 

Managed Package Redirecting Problem

Hi,

I am working on a Flex application integration with Salesforce.

It was working fine until i created a managed package. Now it  gives Page test2__MyExamplePage does not exist message.

I developed the application and created the managed package in my Test Account 1. Managed package namespace is test1.

I installed managed package to my Test Account 2. It also has a namespace named test2.

The problem is in this code:

 

/apex/MyExamplePage?objectId={!Campaign.Id}&returnUrl={!URLFOR( $Action.Campaign.View , Campaign.Id)}

 

And this code is defined in my object's custom button. Content Source is URL.

 

Whenever I click that button from Test Account 2, it tries to find test2.na6.salesforce.com/apex/MyExamplePage?xxxxxxxxxx.

 But it should try to connect to test1 namespace.

 

How can I forward it to the right namespace?

 

Thanks,

Umut

Best Answer chosen by Admin (Salesforce Developers) 
umutdoganumutdogan

We fixed the problem.

 

First we added a new Apex Class by this way:

 

global class PageUrl { webService static String getPageUrl(String objectId) { PageReference p = Page.MyExamplePage; p.getParameters().put('objectId', objectId); return p.getUrl(); } }

 

 Then changed the Related List button's Behavior to Execute Javascript and Content Source to OnClick JavaScript. Called PageUrl class' getPageUrl() method from Javascript:

 

 

{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")} {!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")} var pageUrl = sforce.apex.execute("mynamespace.PageUrl", "getPageUrl", {objectId:"{!Campaign.Id}"}); window.location.href = pageUrl;

 

 It works fine on both namespaces.

 

Thank you again for your suggestions. Do you think it is an elegant solution or is there a better and faster way to do it?

 

Thanks,

Umut

 

 

All Answers

mtbclimbermtbclimber

umutdogan wrote:

 

How can I forward it to the right namespace?

 


By not doing this:

 


 

/apex/MyExamplePage?objectId={!Campaign.Id}&returnUrl={!URLFOR( $Action.Campaign.View , Campaign.Id)}


And instead doing this:

 

{!URLFOR($Page.MyExamplePage,'',[objectId = campaign.id])}

 


 

 

 

Hardcoding URL paths to pages, standard/custom object actions, etc should be avoided. You seem to be doing this with the campaign view action so I assume you just missed the $Page global for linking pages from other pages.

 

You can also use the Page system namespace in Apex to generate appropriate PageReference objects for navigation in your controllers, e.g:

 

 

PageReference p = Page.MyExamplePage; p.getParameters().put('objectid', campaign.id); return p;

 

Linking in these ways shields you from worrying about namespaces and also establishes system integrity and the references that will assist you in not forgetting to include an important element in your package. Right now our system has no idea that your package needs to include the MyExamplePage Visualforce page since the reference is based on a string.

 

 

umutdoganumutdogan

But it gives an error:

 

Error: Field $Page.MyExamplePage does not exist. Check spelling.

 

 

But that page is there.It is my custom VisualForce Page and i tried these possibilities:

 

- {!URLFOR($Page.MyExamplePage,'',[objectId = campaign.id])}

 

- {!URLFOR($Page.test1__MyExamplePage__c,'',[objectId = campaign.id])}

 

- {!URLFOR($Page.MyExamplePage__c,'',[objectId = campaign.id])}

 

None of above worked.

 

Any idea?

 

 

Thanks,

Umut

Message Edited by umutdogan on 02-24-2009 07:28 AM
mtbclimbermtbclimber
Is the page containing the link in the same package as the page you are linking to or are they different?
umutdoganumutdogan

@mtbclimbler

Link is inside the my custom object's custom button as a URL. And this object is installed as a managed package. So the object is also linking to a tab inside the managed package. For example if my account's namespace is x, and if the installed managed package's namespace is y, then its linking to the namespace y. (y.na6.salesforce.com.........) But with my approach it's trying to find the tab (page) in namespace x. (x.na6.salesforce.com.........) As a result i'm getting a not found error.

 

I need to link it to the managed package's namespace. Do you have any idea?

 

Thanks in advance,

Umut

mtbclimbermtbclimber
Why aren't you using a Visualforce custom button type instead of a URL?
umutdoganumutdogan

We're selecting a List Button from Display Type of our custom object's custom buttons and links section.

When we set the Content Source to Visualforce  Page it doesn't display our page in Content section. But if we select Detail Page Button or Detail Page Link from Display Type it displays our custom page (CustomPage__c).

 

Our visualforcepage code is like this:

 

 

<apex:page standardController="OurCustomObject__c"> <apex:sectionHeader title="Auto-Running Apex Code"/> <apex:outputPanel > Example message here... </apex:outputPanel> </apex:page>

 

 

 

 

Even if this works we don't know how to get a handle to the Campaign that this custom button was displayed under.

 

Do you have any more idea?

 

Thanks,

Umut

Message Edited by umutdogan on 02-25-2009 03:39 AM
umutdoganumutdogan

We fixed the problem.

 

First we added a new Apex Class by this way:

 

global class PageUrl { webService static String getPageUrl(String objectId) { PageReference p = Page.MyExamplePage; p.getParameters().put('objectId', objectId); return p.getUrl(); } }

 

 Then changed the Related List button's Behavior to Execute Javascript and Content Source to OnClick JavaScript. Called PageUrl class' getPageUrl() method from Javascript:

 

 

{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")} {!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")} var pageUrl = sforce.apex.execute("mynamespace.PageUrl", "getPageUrl", {objectId:"{!Campaign.Id}"}); window.location.href = pageUrl;

 

 It works fine on both namespaces.

 

Thank you again for your suggestions. Do you think it is an elegant solution or is there a better and faster way to do it?

 

Thanks,

Umut

 

 

This was selected as the best answer
mtbclimbermtbclimber

umutdogan wrote:

We're selecting a List Button from Display Type of our custom object's custom buttons and links section.

When we set the Content Source to Visualforce  Page it doesn't display our page in Content section. But if we select Detail Page Button or Detail Page Link from Display Type it displays our custom page (CustomPage__c).


 

 

Please review Chapter 5 and the section titled "Adding Custom List Buttons using Standard List Controllers" in the Visualforce developer guide (starting with pages 44 and 80 in the PDF).

 

 

I'm not sure exactly what your page does but there is a good chance the standard set controller for your custom object will make what you are doing easier.

 

AffinaquestAffinaquest

I'm having a similar problem to this.  I am trying to create a custom button on a custom object to link to a visualforce page.  The page I want to link to does not use the same controller as the page from which i am linking, so I can't use "Visualforce page" as the content source.

 

When I use "URL" as the content source and {URLFOR($page.mypage)} as the URL, I get a get a page with a "URL no longer exists" message.

 

I am building an application which will become a managed package on the appexchange, so I want to insure that whatever I create can be universally installed.

 

I'd sure appreciate some guidance on this so I don't run into a lot of problems in future installations.

 

Thanks,

Jeff

mtbclimbermtbclimber

Affinaquest wrote:

 

...

The page I want to link to does not use the same controller as the page from which i am linking, so I can't use "Visualforce page" as the content source.

 


 

Can you elaborate and explain the use case please?

 

Thanks,

AQAQ

I'm trying to set up a help system for standard objects (explaining my changes) and custom objects.  I'm not overriding the help links on the custom objects because I don't know what the future will be for the s-control that's required and because I can't override the help link on the standard objects without overriding all help links in the system.

 

I was considering putting custom buttons on each object which would link to a visualforce page powered by a "help" controller which would contain links to my help system as well as allow a site to add some local help (this will be in a managed package marketed on the AppExchange).

 

In order to use a button going to a Visualforce page, I need to have the page use a controller based upon the specific object where the button is located.  Since I will need to place a button on each object in the system, I could end up having to set up dozens of pages. 

 

I would prefer linking to a single page from all the buttons, sending a parameter with the link which would indicate to the page which help is to be displayed.

 

Jeff

 

PS - sorry for the delay in responding.  Apparently the email when someone replies didn't work.

Daniel BallingerDaniel Ballinger

Hi, Apoligies to drag up an old thread.

 

Hasn't the problem of the namespace reference just been moved into the javascript?

 

I.e. it needs to reference mynamespace.

sforce.apex.execute("mynamespace.PageUrl", "getPageUrl", {objectId:"{!Campaign.Id}"})
SiimSiim

 

Yes I agree with Daniel because am facing the same issue too and I have around 15 custom buttons. Has anyone come up with a solution of not referencing namespaces when it comes to custom buttons referencing VF pages like this?

/apex/MyExamplePage?objectId={.....}?

 Thanks,

Siim

TehNrdTehNrd

Yup, this is still a problem for package developers.

Let's say you have a generic page like  /apex/showInfo?id=00bA0000000MoDx .

 

This page does not use a standard controller so using a custom button that launches a Visualforce page wont work. The controller and page are very dynamic. It can look at the id parameter, determine the object type, query the object, and then display data about the object on the page. The link above would show Account information but it could very well show Opportunity information as well with a url like this, /apex/showInfo?id=006A000000GjxQ7.

 

Once this this button is ready for packaging the url must be, /apex/namespace__showInfo?id=00bA0000000MoDx.

 

Using URLFOR($Page.showInfo,[params]) does not work. Ideally this work just work and I think this is the best solution.

 

Without URLFOR working other alternatives could be a merge field like {!$System.isNamespace} or even {!$System.Namespace}. Then we could make these button URLs truly dynamic depending if a namespace is present or not.

 

This would help greating with team development on Force.com where it is typical for all devs to have their own non-namespaced org in which they do their work and it is then merged into the packaging org which has a namespace.

 

-Jason

Chirag MehtaChirag Mehta

thank you, this helped!