0

I'm trying to setup an anonymous account for users to post with.

try{
        system.debug('-------forum_ctl ' + UserInfo.getName());

        pageReference pr = Site.login('[email protected]', 'Abcd1234', null);
        system.debug('-------forum_ctl -after login ' + UserInfo.getName());
        }

This piece of code is in a controller called by my VisualForce page, and looking at the debug logs, there ought to be two different users displayed, since Site.login has been called. This should switch the user from the guest user to the anonymous user, but doesn't.

Any help is appreciated!

3
  • Are you executing this code from a Site?
    – Keith C
    May 28, 2015 at 10:20
  • Yup. Our site does not have a community license, and I've made suer we're running this from a Site
    – user879559
    May 28, 2015 at 10:32
  • OK. I suggest you dump out the content of ApexPages.getMessages() and see if anything is recorded there; I have this comment // May return null and add errors in some code that uses that method.
    – Keith C
    May 28, 2015 at 10:57

1 Answer 1

1

Site.Login(username,password,returnURL) returns the PageReference to which the logged user will be redirected. It won't change the user context from Site Guest User to Site User here. The context will change once the PageReference is loaded(i.e. Redirected to that page).

Hope it helps.

4
  • Thanks for your comment! Unfortunately, I've tried this and it seems that Site.login is returning null. Any ideas why?
    – user879559
    May 29, 2015 at 6:17
  • Try using '/home/home.jsp' in returnURL. If Site.Login(username,password,'/home/home.jsp') returns null, then the problem is with the username and password. May 29, 2015 at 6:32
  • Hmm, Site.login is still returning null, and I've tried to password to login to the sandbox, and can confirm that the username/password is correct. Any other ideas?
    – user879559
    May 29, 2015 at 6:53
  • Can you check the url of the login page? We faced the same issue of site.login() returns null when the login page is http:// and when we changed to https:// site.login() returned the pagereference. Aug 26, 2015 at 6:34

You must log in to answer this question.

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