I need to prevent duplicate names from been entered. This restriction needs to be imposed using a trigger. I want to know how i can restrict the DML operations from happening. Not sure of the usage of .addError in bulkified code.
Set<string> Seta= new Set<string>();
for(oj__c o:trigger.new)
{
Seta.add(c.name);
}
List<oj__c> listoj= new List<oj__c>();
listoj=[select id from oj__c where name in :Seta]
if listoj.size()>0
trigger.new.adderror('Cannot have duplicate name');// i know this line is wrong. How can i stop the DML statement from excuting?
A good reference to what i was looking for could be found here.
http://www.salesforce.com/docs/developer/cookbook/Content/apex_dedupe.htm