2

I am working on trying to pass a variable from one VFP to another. Currently, I'm doing the Site.login(username, password, startUrl), and I technically can pass in a variable through the URL, however I don't want to do it that way.

Here is what I've got currently:

    PageReference loginResult = null;
    String startUrl = '/LoginRedirect?un='+username;
    loginResult = Site.login(username, password, startUrl);
    if (loginResult == null){
        this.result = 'Please check your username and password.';
    }
return loginResult;

Any ideas on the best practice way to pass a variable from this page to the next? If it makes a difference, both pages are using the same Controller.


EDIT:

Trying to do this and when I hit the 'login' button I'm getting redirected to an error page.

    PageReference loginResult = null;
    loginResult.getParameters().put('id', username);
    String startUrl = '/LoginRedirect';
    loginResult = Site.login(username, password, startUrl);

    if (loginResult == null){
        this.result = 'Please check your username and password.';
    }

return loginResult;
}

The actual error from logs is as follows

21:41:47.0 (19743152)|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object --- on the 'loginResult.getParameters().put('id',username);

5
  • 1
    You can use pagereference method itself to pass the start URL . Jan 31, 2016 at 20:15
  • Made an edit of going with the pagereference Jan 31, 2016 at 20:38
  • 1
    CHeck your debug logs to figure whats the error ?In sites if error occurs page is redirected automatically to the error page configured . Jan 31, 2016 at 21:33
  • Getting: 21:41:47.0 (19743152)|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object --- on the 'loginResult.getParameters().put('id',username); line Jan 31, 2016 at 21:43
  • 1
    This simply means your username parameter is null here . Jan 31, 2016 at 22:10

1 Answer 1

2

Looking at the error from the logs ,looks like the user is not instantiating the pagereference object here

Below can be resolution for same

 PageReference loginResult = new PageReference();
  String startUrl = '/LoginRedirect?un='+username;
  loginResult = Site.login(username, password, startUrl);
  if (loginResult == null){
    this.result = 'Please check your username and password.';
 }
return loginResult;
2
  • Trying to pass the parameter without using it in the URL. Assigning the PageReference () piece worked, but as for passing a variable through the loginResult.getParameters().put('id', username); I'm coming up short. Jan 31, 2016 at 23:02
  • Actually I should be set... got it working. Jan 31, 2016 at 23:06

You must log in to answer this question.

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