You need to sign in to do that
Don't have an account?
prevent duplicate records in accounts by using handler class
scenario: how do prevent the duplicate record:
already i tried in list it workedmfor my practice i am trying map.i facing problem kindly someone help me
handler class:
public static void preventDuplicate1(Map<Id,Account> recmap){
Map<Id,Account> mapacc = new Map<Id,Account>([select Id,Name from Account where Name =:recmap.values().Name]);
system.debug(mapacc.values());
for(Account acc:mapacc.values()){
if(acc.name != recmap.get(acc.Id).Name){
acc.Name.addError('cannot use the rename');
}
}
}
trigger :
trigger AccountDescription on Account (before insert,before update,after insert,after update,before delete,after delete,after undelete) {
if(Trigger.IsBefore && Trigger.IsInsert){
AccoutBeforeInsert.preventDuplicate1(Trigger.newMap);
}
can anyone help this?
Try Below Code Please Mark It As Best Asnwer If It Helps
Thank You