+ Start a Discussion
Imtiaz PashaImtiaz Pasha 

Hi all i want to write a duplicate rule in salesforce where same number shouldnt enter it plz help me

CharuDuttCharuDutt
Hii Imtiaz Pasha
Can You Please Explain More About Requirement 
Imtiaz PashaImtiaz Pasha
Hi Charu,

the perosn creates the lead with same number, and that lead already present in salesforce , shouldn't create the lead , its should throw an error creating an duplicate lead.

also i want to avoid the same number entering multiple times in salesforce , only unique number should be there , i want to write dupliactes rule for this plz help 
CharuDuttCharuDutt
Hii Imtiaz Pasha
Try The Below Trigger
Number__c  is Number Field In lead object in My Org You Can Replace The Field Want To Restrict From Duplication

Trigger preventDuplication on Lead(before insert, before update) {
Set<string> numSet = new Set <string>() ;
If (trigger.IsBefore) {
    If(trigger. Is Insert || trigger.IsUpdate){
        For(lead led: trigger.new){
                  numSet.add(led.Number__c);
               } 
           } 
      } 

List<Lead> lstled = [select Id, Number__c from Lead where Number__c in :numSet];

For(Lead led2 : trigger.new){
   If(lstled.size()>0){
       led2.Number__c.adderror('duplicate Number found');
   }
​​​​​​}
Please Mark It As Best Answer If It Helps
Thank You!

 
Imtiaz PashaImtiaz Pasha
can you please help me to use the front end  funcitonlity which is already their in salesforce duplication rules.
instead of using the lead trigger .
SwethaSwetha (Salesforce Developers) 
HI Imtiaz,
Can you set up duplicate rule with matching criteria as below and see if that helps

Matching CriteriaLead: NumberOfLeadExactMatchBlank = TRUE

Related:https://www.salesforceben.com/6-salesforce-duplicate-rules-you-need-to-activate-right-now/
https://trailhead.salesforce.com/content/learn/modules/sales_admin_duplicate_management/sales_admin_duplicate_management_unit_2