function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
B TulasiB Tulasi 

Login page is blank while click the login button.

Hi All,

       I am getting page is blank, while click the login button.I didn't get any error before saving the code. While loging the page, it will be blank page

VF CODE :

<apex:page controller="Sample" sidebar="false" >
<apex:form >
<apex:pageBlock >

    <br>UserName&nbsp;<apex:inputText label="center" value="{!userName}"/></br>
    <br>Password &nbsp;&nbsp;<apex:inputsecret value="{!password}"/></br>    
    <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <apex:commandButton value="Login" action="{!loginPage}" reRender="Error"/></br>
    <br><br>
    <apex:outputLink value="https://c.ap2.visual.force.com/apex/RegistrationPage">Create New Account</apex:outputLink>
    </br></br>
    <apex:pageMessages id="Error"></apex:pageMessages>
    
</apex:pageBlock>
</apex:form>
</apex:page>





Controller :

public class Sample {     
    public String userName{get;set;}
    public String password{get;set;}
    public List<Registration__c> returns {get;set;}
   
    public Sample(){
   
      returns = new List<Registration__c>();
    }  
   
    public PageReference loginPage(){
   
        returns = [select ID, Name, User_Name__c, Password__c from Registration__c Where User_Name__c=:userName and Password__c=:password];
        if(!returns.isEmpty()) {
            Pagereference pr = new PageReference('/'+returns[0].id);
            pr.setReDirect(false);
            return pr;
        }
        else {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Invalid UserName or Password'));
                return null;
        }
        //Pagereference pr = new PageReference('/'+returns[0].Id);
        //pr.setRedirect(true);
        //return pr;
        return null;
    }

}

Plead Identify the error, what is missing here.

Thanks in advance
Thulasi
 
Nitin Paliwal 9Nitin Paliwal 9
Hi Thulasi,
In the controller method "login Page", 
if(!returns.isEmpty()) {
            Pagereference pr = new PageReference('/'+returns[0].id);
            pr.setReDirect(false);
            return pr;
        }

you need to set " pr.setReDirect" as "true" rather then false. So your method would look like this:

if(!returns.isEmpty()) {
            Pagereference pr = new PageReference('/'+returns[0].id);
            pr.setReDirect(true);
            return pr;
        }

I think this would resolve your error.

Thanks
Nitin
B TulasiB Tulasi
Hi Nithin,

Thanks for ur reply, First i tried with "true" value, aftere i changed it as false. But, the same error.