You need to sign in to do that
Don't have an account?
Procurement Executive
Can we use duplicate rule in trigger?
Can we use duplicate rule in trigger?
I have a requirement where I need to update contacts if duplicate contact gets created or added.
I have a requirement where I need to update contacts if duplicate contact gets created or added.
Instead of addError you can do what you want with the duplicated or existing record.
If it helps please like and mark as correct as it may help others.
trigger EliminateDuplicateAcc on Account (before insert) {
map<string,Account> AccNameMap = new map<string,Account>();
List<string> AccNameList = new List<string> ();
for(Account Acc : Trigger.new){
AccNameList.add(Acc.Name);
AccNameMap.put(Acc.Name, Acc);
}
List<Account> AccList = [Select Id,Name from Account where name=:AccNameList];
If (AccList.size()>0){
for (Account Acct : Trigger.new){
if(AccNameMap.containsKey(Acct.Name)){
Acct.adderror(Acct.Name + ' already exist!! Duplicates not allowed');
}
}
}
}
If it helps, please like and mark as correct as it may help others.