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
prasanth kumarprasanth kumar 

simple trigger for duplicate names not working please help me

hi dudes,  in student123__C  detail page there are 3 fields,  firstname__c. lastname__c, middlename__c   .   i need to write a trigger to check "if a person is entering the same values then, throw an error that "duplicate contact found".   

Example:-   1st record i entered as  "  Siva Naga Raju "      so if am again entering this same name then it should throw an error.    

For that i created a forumla field   called TOTALNAME__C  ( firstname__c + lastname__c + middlename__c).  upto here ok.   But trigger not firing, intially i worte bulk trigger, but its not firing, so i wrote a simple trigger then, it is also not firing,   please some boby help me. thanks in advance.


 
trigger duplicatefullname on student123__c (before insert,before update) {

string name;
list<student123__c> databasenames;
for(student123__c stu:trigger.new)
{
name=stu.firstname__c+stu.lastname__c+stu.middlename__c;
databasenames=[select totalname__C from student123__c where totalname__C=:name];
if(databasenames.size()>0)
stu.adderror('another jaff found');

}
    
}

User-added image
Cloud_forceCloud_force
trigger looks okay. follow below steps to debug the issue
1. Check if your trigger is active
2. Put debug logs to see values of the total name and string name
3. your trigger may not work for insert as formula field may not have values during insert so just try for update

You can also do this using configuration only but may need few considerations.
here is a post that explains how duplicate check can be done using configuration only: http://www.cloudforce4u.com/2013/06/record-duplication-validation-using.html