I have a button which takes the user to a new page and passes through an Id parameter. I eventually want to package these into an app, which will mean there will be a namespace. How do I do this easily? I have the following code now, which I think will fail once packaged?

    public PageReference myPageLink(){ 
      return new PageReference('/apex/MyPageAboutCases?Id='+caseId);

I think you should use explicit reference so it doesn't breaks while packaging.

PageReference p = Page.TheVisualforcePage;

 p.getParameters().put('id', caseId);

Daniel Ballinger has an excellent post on this: Safe URLs for custom buttons and page references


You can use this:

PageReference myPage = Page.MyPageAboutCases;
myPage.getParameters().put('id', caseId); 

Check out this: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_system_pagereference.htm

And this: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/apex_System_PageReference_methods.htm

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.