[SalesForce] Redirecting to Custom Customer Portal Login Upon Failed Login

My company Is still using a portal for their customer login, and I was recently tasked with creating a VF page to replace the bland default login page. I have most of the page set-up, but I cannot get the page to redirect back to itself on a failed login; instead, it goes to the default login page. I'm using the code I found in other question pages for determining if a login succeeded or failed, by checking if the pageReference returned by a login is null:

    //set reference and attempt login
    PageReference portalPage = new PageReference(startUrl);
    portalPage.setRedirect(true);
    PageReference p = Site.login(username, password, startUrl);

    //if login==false return to custom login
    if (p == null) return Site.login(username, password, null);
    //else enter portal
    else return portalPage;

This code, however, always redirects to custom login pagen (p is always null). In experimentation, I simply returned portalPage, and it makes it so that it only redirects to the default login (or the portal itself on successful login. As such, I am convinced that the "p == null" bit is not successfully determining the login status, though it seems to work for everyone else. If anyone could offer some advice as to how I might go about fixing this, I would much appreciate it.

For reference, I used the exact same method I found here:
https://developer.salesforce.com/forums/ForumsMain?id=906F000000096YkIAI

Best Answer

Please use rerender and apex:pagemessages component on the page you designed. So that we can know what's the exact issue is. Did you try checking debug logs.

Related Topic