String startURL = '/PageALanding';
        String retUrl = 

        if(retUrl != null){
            return Site.login(username, password, retUrl);

        PageReference pr = Site.login(username, password, startUrl);

        if (pr == null){
            loginError = true;

        return pr;
  • It does return null in a test or other non-Site context. Also make sure you have apex:pageMessages in your page because the call adds error messages. In general, add more context to your question.
    – Keith C
    Jun 26, 2017 at 17:21
  • The error message displayed on the page : ERROR Your login attempt has failed. Make sure the username and password are correct.
    – V C
    Jun 26, 2017 at 17:25
  • Have you created the right kind of User according to how your Site is configured? Reset the password if you have lost that.
    – Keith C
    Jun 26, 2017 at 17:31


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.