You need to sign in to do that
Don't have an account?
Rahul
Hello Friends, I have a small issue in login Visualforce page. After entering username then date and clicking on login, its giving Null error. Its not querying date and Please have a look
When I eneter User name and Date in the input fields then click on login button , it should check whether that User name which Iam referring to last name in lead and that date of birth is present in the Lead. If its present then it should Login and redirect to a visualforce page. Its working fine if iam doing without date when when Iam querying date its throwing the Null pointer exceptio, Attempt to reference null object error. I think its error in the query.Date should be converted in hh:mm:ss i guess please help.
Please find the code.
public with sharing class LoginCntrl {
public string userName{get;set;}
public Lead Dateofbirth{get;set;}
public pageReference doLogin() {
if(String.isBlank(userName)) return null;
string dateformat;
List<Lead> conls = [select id, lastname from Lead where LastName = :userName and date_of_birth__c=:Dateofbirth.Date_of_Birth__c];
system.debug('dddddddddddddddddd'+conls );
if(conls.size() == 1 ) {
return new pageReference('/apex/studentpersonaldetails');
}
else {
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Please Enter correct User Name or Date of Birth'));
userName = null;
Dateofbirth = null;
return null;
}
}
}
VF :-
<apex:page controller="LoginCntrl" showHeader="false" sidebar="false">
<apex:form >
<apex:image id="theImage" value="{!$Resource.nmims2}" width="350" height="60"/><br/>
<apex:pageBlock title="Login Page" >
<apex:pageMessages ></apex:pageMessages>
<br/>
User Name : <apex:inputtext value="{!userName}"/> <br/>
<br/>Date of birth: <apex:inputfield value="{!Dateofbirth.Date_of_Birth__c}"/><br/>
<br/>
<apex:commandButton style="margin-left:10px" value="Login" action="{!doLogin}"/>
</apex:pageBlock>
</apex:form>
</apex:page>
Please find the code.
public with sharing class LoginCntrl {
public string userName{get;set;}
public Lead Dateofbirth{get;set;}
public pageReference doLogin() {
if(String.isBlank(userName)) return null;
string dateformat;
List<Lead> conls = [select id, lastname from Lead where LastName = :userName and date_of_birth__c=:Dateofbirth.Date_of_Birth__c];
system.debug('dddddddddddddddddd'+conls );
if(conls.size() == 1 ) {
return new pageReference('/apex/studentpersonaldetails');
}
else {
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Please Enter correct User Name or Date of Birth'));
userName = null;
Dateofbirth = null;
return null;
}
}
}
VF :-
<apex:page controller="LoginCntrl" showHeader="false" sidebar="false">
<apex:form >
<apex:image id="theImage" value="{!$Resource.nmims2}" width="350" height="60"/><br/>
<apex:pageBlock title="Login Page" >
<apex:pageMessages ></apex:pageMessages>
<br/>
User Name : <apex:inputtext value="{!userName}"/> <br/>
<br/>Date of birth: <apex:inputfield value="{!Dateofbirth.Date_of_Birth__c}"/><br/>
<br/>
<apex:commandButton style="margin-left:10px" value="Login" action="{!doLogin}"/>
</apex:pageBlock>
</apex:form>
</apex:page>
All Answers
Visualforce Error
System.NullPointerException: Attempt to de-reference a null object
Error is in expression '{!doLogin}' in component <apex:commandButton> in page loginpage: Class.LoginCntrl.doLogin: line 9, column 1
Class.LoginCntrl.doLogin: line 9, column 1
Could not resolve the entity from <apex:inputField> value binding '{!Dateofbirth}'. <apex:inputField> can only be used with SObjects, or objects that are Visualforce field component resolvable.