Is that possible to pass an parameter without exposing in the URL?

public PageReference goToNextPage() {
    PageReference pageRef = Page.MyNextPage;
    pageRef.getParameters().put('AccId', accountId);
    return pageRef;

it shows in the url


But I would like that not to show in the URL, the above is just an example and I have couple of parameters that I'm passing but the requirement is not to expose to the end user, have anybody done similar or have an idea how to do that?

  • 1
    The key question is: why do you care?
    – Adrian Larson
    Jan 30 '17 at 3:21
  • customer care and its part of requirement.
    – Nick Kahn
    Jan 30 '17 at 3:22
  • 2
    Just because they say it matters doesn't mean you should listen to them. Get a concrete justification for why, otherwise it's frivolous nonsense.
    – Adrian Larson
    Jan 30 '17 at 3:23
  • also the part of that is the same concept so when you go to the salesforce and XXXX.salesforce.com/type_id_here it will let you redirect to the page based on the id... and restricting the end-user changing the ids
    – Nick Kahn
    Jan 30 '17 at 3:24
  • @NickKahn - if you are passing params via url, even if you do not show them the user could still change the url like they were there and by design your controller would handle them
    – Eric
    Jan 30 '17 at 4:24

You can do one of two things:

  1. Set redirect to false. The URL in the browser should not be updated. Could cause issues depending on the circumstances and the page redirected to must be using the same controller)
  2. Encode the parameters and decode them in the controller which may satisfy your requirements

But ask yourself first like Adrian said, why does it matter?

  • Another not so easy option would be to store parameters in browser cookies and reading those from the new page but again it is not worth the extra effort.
    – javanoob
    Jan 30 '17 at 4:12
  • Third totally overkill option: encrypt the parameters and decode them in your Apex Code.
    – sfdcfox
    Jan 30 '17 at 4:17
  • The first option will not work. SetRedirect to false will not work if the two pages are of different controllers. Even if they are of the same thing, it will not trigger the constructor firing again which means the parameter passed will not work.
    – Lance Shi
    Jan 30 '17 at 4:29

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.