You need to sign in to do that
Don't have an account?
sampath palli
I have an requirement i need to verify details existing in sobject using SOQL for example that i have an custom object with fields name,password and i have vf page like login page. before login first i need to check weather the given name and password which are given in login page is existed in object or not,If details are existed then go to home page Else it show message enter valid details
Please go through my code:
apex code:
public class loginapex_Rum {
public String rname{set;get;}
public String pwd{set;get;}
public list<Registartion__c>result{set;get;}
public pagereference register(){
pageReference p=new pageReference('/apex/RegistrationPage_Rum');
return p;
}
public pageReference go(){
pageReference p=new pageReference('/apex/Home');
return p;
}
public void getdetails(){
result=[select Rum_Name__c,Password__c from Registartion__c];
for(Registartion__c r:result){
if(r.Rum_Name__c==rname&&r.Password__c==pwd){
go();
}else{
}
}
}
}
vf page:
<apex:page controller="loginapex_Rum">
<apex:form >
<apex:pageBlock title="Login" >
<apex:pageBlockSection columns="1">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Enter Rum Name"/>
<apex:inputText value="{!rname}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Enter Password" />
<apex:inputSecret value="{!pwd}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:commandButton value="Login" action="{!getdetails}"/>
<apex:commandButton value="SignUp" action="{!register}"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockSection columns="2">
<apex:pageBlockSectionItem >
<nbsp></nbsp>
<apex:commandLink value="Forget Password"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
problem in data verification using SOQL to login
I have an requirement i need to verify details existing in sobject using SOQL for example that i have an custom object with fields name,password and i have vf page like login page. before login first i need to check weather the given name and password which are given in login page is existed in object or not,If details are existed then go to home page Else it show message enter valid details
Please go through my code:
apex code:
public class loginapex_Rum {
public String rname{set;get;}
public String pwd{set;get;}
public list<Registartion__c>result{set;get;}
public pagereference register(){
pageReference p=new pageReference('/apex/RegistrationPage_Rum');
return p;
}
public pageReference go(){
pageReference p=new pageReference('/apex/Home');
return p;
}
public void getdetails(){
result=[select Rum_Name__c,Password__c from Registartion__c];
for(Registartion__c r:result){
if(r.Rum_Name__c==rname&&r.Password__c==pwd){
go();
}else{
}
}
}
}
vf page:
<apex:page controller="loginapex_Rum">
<apex:form >
<apex:pageBlock title="Login" >
<apex:pageBlockSection columns="1">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Enter Rum Name"/>
<apex:inputText value="{!rname}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Enter Password" />
<apex:inputSecret value="{!pwd}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:commandButton value="Login" action="{!getdetails}"/>
<apex:commandButton value="SignUp" action="{!register}"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockSection columns="2">
<apex:pageBlockSectionItem >
<nbsp></nbsp>
<apex:commandLink value="Forget Password"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
public class loginapex_Rum
{
public String rname{set;get;}
public String pwd{set;get;}
public list<Registartion__c> result{set;get;}
public pagereference register()
{
pageReference p=new pageReference('/apex/RegistrationPage_Rum');
return p;
}
public pageReference go(){
pageReference p=new pageReference('/apex/Home');
return p;
}
public pageReference getdetails()
{
result=[select Rum_Name__c,Password__c from Registartion__c where Rum_Name__c = :rname and Password__c =:pwd ];
if(result.size() > 0 )
{
go();
}
else
{
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Invalid Password'));
return null;
}
}
}
Let us know if this will help you
All Answers
Controller,
VF page,
1) http://www.sfdcpoint.com/salesforce/show-error-message-visualforce-page/
2) http://www.infallibletechie.com/2012/10/how-to-display-error-messages-in.html
3) http://www.infallibletechie.com/2013/04/how-to-add-error-message-in-visualforce.html
To display error messages in the Visualforce page add below tag where you want to display the error message.
Visualforce page:
<apex:pageMessages />
Apex Controller:
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error Message.');
ApexPages.addMessage(myMsg);
Let us know if this will help you
Thanks for your reply
when i run your suggested code it throws error:"Initial term of field expression must be a concrete SObject: List<Registartion__c>"
Again it's fires error like"Illegal assignment from Registartion__c to List<Registartion__c>" in line No:18
is their any alternate way to verify login details
Please try below code.
Controller :- Page :- Let us know if this will help you
Thanks
Amit Chaudhary
I tried ur code but it gives error like "Void method must not return a value" And i checked by removing the return statements and when i trying to login it gets error please check this clip
Thanks for ur reply,
I tried your code it don't get any error but when i tried to login with existing details it doesn't go to the home page, I think go() method doesn't calling in getdetails() method, And if i give wrong details in login page it don't fires error message
public class loginapex_Rum
{
public String rname{set;get;}
public String pwd{set;get;}
public list<Registartion__c> result{set;get;}
public pagereference register()
{
pageReference p=new pageReference('/apex/RegistrationPage_Rum');
return p;
}
public pageReference go(){
pageReference p=new pageReference('/apex/Home');
return p;
}
public pageReference getdetails()
{
result=[select Rum_Name__c,Password__c from Registartion__c where Rum_Name__c = :rname and Password__c =:pwd ];
if(result.size() > 0 )
{
go();
}
else
{
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Invalid Password'));
return null;
}
}
}
Let us know if this will help you
Thanks for ur reply I tried ur code and made small change in code we need to use "return go()"