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
bremmibremmi 

validation of record using vf,apex,and custome object

hai,

i  have two fields like username and password on vf page. i want  to validate the username and password form that is already stored in an custome objeect . when both values were matched it redirect to  another page

Best Answer chosen by Admin (Salesforce Developers) 
bremmibremmi

i  wrote code what ever your given according to my custome object but it is not returning the result.even when i wrote wrong   username and password .it doesnt return page. when i enter correct details the page just  got refreshed.

All Answers

Wonder WomanWonder Woman

How about:

 

public PageReference Login() {  

              

               try{      

                            Login_Custom_Object__c login = [Select Id From Login_Custom_Object__c

                                                                                   Where Username__c = : username

                                                                                   And Password__c = : password]);  

               } catch (Exception ex)

               {   

                            ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Invalid Password'));                              return null;   

               }

    

               PageReference page = new PageReference('URL');  

               page.setRedirect(true);  

               return page;

}

bremmibremmi

i  wrote code what ever your given according to my custome object but it is not returning the result.even when i wrote wrong   username and password .it doesnt return page. when i enter correct details the page just  got refreshed.

This was selected as the best answer
Wonder WomanWonder Woman

Can you share your code here?

bremmibremmi

vf page:

 

<apex:page controller="hyd">
<center><font color="red" > Hyderabad Blood Donors</font></center>

<apex:form >

<apex:tabPanel switchType="client" selectedTab="tab1">
<apex:tab name="Home" label="home" id="tabone">
<apex:pageBlock >

<apex:sectionHeader title="Hyderabad blood donor" subtitle="A Voluntary Blood Donor Database"/>
<table WIDTH="100%" >

<td>
Welcome To Hyderabad Blood Donors <br/>
<br/>
<br/>Every Year Thousands of units of blood is required in and around Hyderabad and Secunderabad. HyderabadBloodDonors.org is an online platform where donors and recipients or patients could meet together. Our charitable blood donors donate blood for emergency need, the needy and natural calamities.
<br/>
<br/>
HyderabadBloodDonors.org which is under the aegis of Lions Club Of Secunderabad Pearls is a non-profit, non-commercial online boundary of social dedication which is a device to use the power of the Internet to help common people and does not deal in blood nor is it a blood bank.
<br/>
</td>
</table>
<table WIDTH="100%" >
<td>
<h1>Facts about blood donation</h1>
<ul type="square">
Facts About Blood donation


<li>GIVING BLOOD IS SAFE!</li>
<li>GIVING BLOOD IS EASY!</li>
<li>GIVING BLOOD IS FAST!</li>
<li>GIVING BLOOD SAVES THE LIVES OF OTHERS!</li>
<li>BLOOD DONATIONS COULD SAVE YOUR LIFE ALSO!</li>
</ul>
</td>
</table>
</apex:pageBlock>
</apex:tab>
<apex:tab name="registration" label="registration" id="tabtwo">
UserName:<apex:inputText value="{!uname}"/>
<br/>Password:<apex:inputSecret value="{!pwd}"/>
<br/>confirm password:<apex:inputSecret value="{!cpwd}"/>
<br/>Firstname:<apex:inputText value="{!fname}"/>
<br/>Lastname:<apex:inputText value="{!lname}"/>
<br/>gender
<apex:selectList id="choosegender" value="{!choosegender}" size="1">
<apex:selectOption itemLabel="male" itemValue="male"></apex:selectOption>
<apex:selectOption itemLabel="female" itemValue="female"></apex:selectOption>
</apex:selectList>
<br/>age:<apex:inputText value="{!age}"/>
<br/>place:<apex:selectList id="place" value="{!place}" size="1" >
<apex:selectOption itemLabel="Select One" itemValue="selectone"></apex:selectOption>
<apex:selectOption itemLabel="adilabad" itemValue="adilabad"></apex:selectOption>
<apex:selectOption itemLabel="anathpur" itemValue="ananthpur"></apex:selectOption>
<apex:selectOption itemLabel="chitoor" itemValue="chitoor"></apex:selectOption>
<apex:selectOption itemLabel="cudapah" itemValue="cudapah"></apex:selectOption>
<apex:selectOption itemLabel="east godavari" itemValue="east godavari"></apex:selectOption>
<apex:selectOption itemLabel="guntur" itemValue="guntur"></apex:selectOption>
<apex:selectOption itemLabel="kamam " itemValue="kamam"></apex:selectOption>
<apex:selectOption itemLabel="karimanagar" itemValue="karimangar"></apex:selectOption>
<apex:selectOption itemLabel="krishna" itemValue="krishna"></apex:selectOption>
<apex:selectOption itemLabel="kurnool" itemValue="kurnool"></apex:selectOption>
<apex:selectOption itemLabel="hyderabad" itemValue="hyderabad"></apex:selectOption>
<apex:selectOption itemLabel="secundrabad" itemValue="secudrabad"></apex:selectOption>
</apex:selectList>
<BR/>blood group:<apex:selectList id="bloodgroup" value="{!bloodgroup}" size="1">
<apex:selectOption itemLabel="Select One" itemValue="Select One"></apex:selectOption>
<apex:selectOption itemLabel="A+" itemValue="A+"></apex:selectOption>
<apex:selectOption itemLabel="A-" itemValue="A-"></apex:selectOption>
<apex:selectOption itemLabel="B+" itemValue="B-"></apex:selectOption>
<apex:selectOption itemLabel="AB+" itemValue="AB-"></apex:selectOption>
<apex:selectOption itemLabel="O+" itemValue="O-"></apex:selectOption>
<apex:selectOption itemLabel="A1+" itemValue="A1+"></apex:selectOption>
<apex:selectOption itemLabel="A1- " itemValue="A1-"></apex:selectOption>
<apex:selectOption itemLabel="A1B+" itemValue="A1B+"></apex:selectOption>
<apex:selectOption itemLabel="A1B-" itemValue="A1B-"></apex:selectOption>
<apex:selectOption itemLabel="A2B+" itemValue="A2B+"></apex:selectOption>
<apex:selectOption itemLabel="A2B-" itemValue="A2B-"></apex:selectOption>
<apex:selectOption itemLabel="BOMBAYBLOOD GROUP" itemValue="BOMBAYBLOOD GROUP"></apex:selectOption>
</apex:selectList>
<br/>Email (if any):<apex:inputText value="{!email}"/>
<br/>address:<apex:inputText value="{!address}"/>
<br/>previous blood donation details:<apex:inputText value="{!pdetails}"/>
<br/>mobile:<apex:inputText value="{!mobile}"/>
<br/><apex:commandButton action="{!save}" value="save"/>
</apex:tab>
<apex:tab name="login" label="login" id="tabthree">
UserName:<apex:inputText value="{!var1}"/>
<br/>Password:<apex:inputSecret value="{!var2}"/>
<br/><apex:commandButton action="{!login}" value="login"/>
</apex:tab>
<apex:tab name="search a donor" label="search" id="tabfour">
<apex:pageBlock title="Search for Blood Donors">

Blood Group&nbsp;&nbsp;<apex:selectList id="bloodgroup1" value="{!bloodgroup1}" size="1">
<apex:selectOption itemLabel="Select One" itemValue="selectone"></apex:selectOption>
<apex:selectOption itemLabel="A+" itemValue="A+"></apex:selectOption>
<apex:selectOption itemLabel="A-" itemValue="A-"></apex:selectOption>
<apex:selectOption itemLabel="B+" itemValue="B-"></apex:selectOption>
<apex:selectOption itemLabel="AB+" itemValue="AB-"></apex:selectOption>
<apex:selectOption itemLabel="O+" itemValue="O-"></apex:selectOption>
<apex:selectOption itemLabel="A1+" itemValue="A1+"></apex:selectOption>
<apex:selectOption itemLabel="A1- " itemValue="A1-"></apex:selectOption>
<apex:selectOption itemLabel="A1B+" itemValue="A1B+"></apex:selectOption>
<apex:selectOption itemLabel="A1B-" itemValue="A1B-"></apex:selectOption>
<apex:selectOption itemLabel="A2B+" itemValue="A2B+"></apex:selectOption>
<apex:selectOption itemLabel="A2B-" itemValue="A2B-"></apex:selectOption>
<apex:selectOption itemLabel="BOMBAYBLOOD GROUP" itemValue="BOMBAYBLOOD GROUP"></apex:selectOption>
</apex:selectList><br/>
Place&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<apex:selectList id="place1" value="{!place1}" size="1">
<apex:selectOption itemLabel="Select One" itemValue="selectone"></apex:selectOption>
<apex:selectOption itemLabel="adilabad" itemValue="adilabad"></apex:selectOption>
<apex:selectOption itemLabel="anathpur" itemValue="ananthpur"></apex:selectOption>
<apex:selectOption itemLabel="chitoor" itemValue="chitoor"></apex:selectOption>
<apex:selectOption itemLabel="cudapah" itemValue="cudapah"></apex:selectOption>
<apex:selectOption itemLabel="east godavari" itemValue="east godavari"></apex:selectOption>
<apex:selectOption itemLabel="guntur" itemValue="guntur"></apex:selectOption>
<apex:selectOption itemLabel="kamam " itemValue="kamam"></apex:selectOption>
<apex:selectOption itemLabel="karimanagar" itemValue="karimangar"></apex:selectOption>
<apex:selectOption itemLabel="krishna" itemValue="krishna"></apex:selectOption>
<apex:selectOption itemLabel="kurnool" itemValue="kurnool"></apex:selectOption>
<apex:selectOption itemLabel="hyderabad" itemValue="hyderabad"></apex:selectOption>
<apex:selectOption itemLabel="secundrabad" itemValue="secudrabad"></apex:selectOption>
</apex:selectlist><br/><br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<apex:commandButton value="Search" action="{!save}"/>

</apex:pageBlock>
</apex:tab>
</apex:tabPanel>

</apex:form>
</apex:page>

 

====================================================

apex code:

 

public class hyd {
bloodbank__c bb=new bloodbank__c();
public String place1 { get; set; }

public String bloodgroup1 { get; set; }


public PageReference login() {

try{
bloodbank__c login = [Select Id From bloodbank__c Where name = : uname And password__c = : pwd];
//system.debug("----------------"+pwd);
} catch (Exception ex)
{
ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Invalid Password'));
return null;
}

PageReference page = new PageReference('www.fb.com');
page.setRedirect(true);
return page;
}


public String var2 { get; set; }

public String var1 { get; set; }

 

public PageReference save() {
bb.name=uname;
bb.password__c=pwd;

insert bb;
return null;
}


public decimal mobile { get; set; }

public String pdetails { get; set; }

public String address { get; set; }

public String email { get; set; }

public String bloodgroup { get; set; }

public String place { get; set; }

public String age { get; set; }

public String choosegender { get; set; }

public String lname { get; set; }

public String fname { get; set; }

public String cpwd { get; set; }

public String pwd { get; set; }

public String uname { get; set; }


}

bremmibremmi
authentication is working perfect but it is not returning error msg when i was entering wrong data. its just refreshed