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

How to check the field uniqueness

Hi Every one,


I am new to my apllication i want check the value of the field.if the value exists i have to dispaly the alert box in VF page.if any one knows plz help me with the code.tell me the correct way to do this functionality.plz help me.

plz tell me how to write the apex class for this page.


Here my code is:

<apex:page standardController="CAF_Bank__c" extensions="cafbank"  >
    <apex:form >
        <apex:pageBlock >
                    <!-- PAGE BLOCK SECTIONS-->
            <apex:pageBlockSection columns="1" showHeader="true" title="CAF Bank Info">
              <apex:inputField value="{!CAF_Bank__c.Bank_Name__c}"/>
              <apex:inputField value="{!CAF_Bank__c.Branch_Code__c}"/>
              <apex:inputField value="{!CAF_Bank__c.Branch_Name__c}"/>
              <apex:inputField value="{!CAF_Bank__c.Credit_Limit__c}"/>
              <apex:inputField value="{!CAF_Bank__c.Manager_Name__c}"/>                      
              <apex:inputField value="{!CAF_Bank__c.Address_1__c}"/>
              <apex:inputField value="{!CAF_Bank__c.Address_2__c}"/>
              <apex:inputField value="{!CAF_Bank__c.Area__c}"/>                       
              <apex:inputField value="{!CAF_Bank__c.City__c}"/>
              <apex:inputField value="{!CAF_Bank__c.Pin_Code__c}"/>
              <apex:inputField value="{!CAF_Bank__c.State__c}"/>
              <apex:inputField value="{!CAF_Bank__c.Country__c}"/>
              <apex:inputField value="{!CAF_Bank__c.Telephone_No__c}"/>                 
              <apex:inputField value="{!CAF_Bank__c.Mobile_Telephone_No__c}"/>
              <apex:inputField value="{!CAF_Bank__c.Fax__c}"/>                                   
            <!-- PAGE BLOCK BUTTONS-->
            <apex:pageBlockButtons location="both">
                <apex:commandButton action="{!save}" value="Save"/>
                <apex:commandButton action="{!cancel}" value="Cancel"/>
            <apex:pageMessages ></apex:pageMessages>





Hi Manu,


Why not just make the field unique, and let the platform check for you automatically.


Hope that helps,



You may set the field as unique in the Custom Fields & Relationships.

That way, the system will check for the uniqueness of that field automatically.


You can also add the apex tag:  <apex:message/> to your page so you will see the errors produced
by the system.


Hope this helps.



- Zeta