5

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);
}

2 Answers 2

2

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

6

I think you should use an explicit reference so it doesn't break 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

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .