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
subhash induri ksubhash induri k 

Unique Formula

I need a Uniqueness to give a Phone field ,,, is this possible? or any Formula have to achive this ... 

please any one help me 
Sagar PareekSagar Pareek
Hi Subhash,

Can you elobrate your requirement in detail?
ManojjenaManojjena
Hi Subash,

Better if you configure duplicate management for the particulat object .Which is inbuit in salesforce . 

Setup>>Administion setup>>Data.com Administration>>Duplicate Management and set the rule for your object and it will not allow you to create record with duplicate phone .

Let me know if it helps .

Thanks 
Manoj
OhtomoOhtomo
If you use workflow and creating new Custom Field.
You create new text type Custom Field and check unique.
So you use workflow that phone number is copied to new Custom Field.
yogesh_sharmayogesh_sharma
Hi Subhash,
You can do your phone number unique using apex:
Trigger:
trigger DuplicatePhoneNumber1 on Account (before insert, before update) {

    DuplicatePhoneNumber objDuplicatePhoneNumber = new DuplicatePhoneNumber();  
   //trigger will get fired before insert
   if(trigger.isInsert && trigger.isBefore) {
       objDuplicatePhoneNumber.duplicateCheckMethodBeforeInsert(trigger.new); 
   }
   //trigger will get fired brfore update
   if(trigger.isUpdate && trigger.isBefore) {
     
        List<Account> lstAccount = new List<Account>();
        
        for(Account objAccount : Trigger.New)
        {
            Account objOldAccount = Trigger.OldMap.get(objAccount.Id);
            
            if(objAccount.Phone != objOldAccount.Phone)
            {
                lstAccount.add(objAccount);
            }
        }
        
    objDuplicatePhoneNumber.duplicateCheckMethodBeforeInsert(lstAccount);
         
   } 
}
Handler:
public with sharing class DuplicatePhoneNumber {

   // Method for check duplicate records before insert.
    public void duplicateCheckMethodBeforeInsert(list<Account> accList){
        Set<String> setPhoneNo=new Set<String>();
          for(Account objAccount:accList){
            if(objAccount.Phone!= null)
            setPhoneNo.add(objAccount.Phone);
        }

        Set<String> setDupPhoneNo = new Set<String>();
        if(setPhoneNo.size()>0){
          for(Account objAccount:[Select Id,
                                         Phone,
                                         Name 
                                  from Account 
                                  where Phone IN:setPhoneNo]){
            setDupPhoneNo.add(objAccount.Phone);
          }
        }

        for(Account objAccount:accList){
          if(setDupPhoneNo.contains(string.valueof(objAccount.Phone))){
            objAccount.addError('Duplicate Phone Number');
          }
        }
   }// End duplicateCheckMethodBeforeInsert
}
Using this piece of code you can do unique your any field. I hope it will help you.
please let me know if you need any additional help. If this helps you, Please check this as a best answer so it will be helpful for others.
Thank You!

 
Abhi_TripathiAbhi_Tripathi
You can perform these for your case
  • Create a text field make it unique External Id.(It will be never duplicate and user cannot insert duplicate values also, duplicate management can allow you to insert anyway)
  • Then create a validation rule to check all the values are numeric otherwise show error.
Done
subhash induri ksubhash induri k
Thank you