• shikha ahuja
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hi,
      trigger AccountDuplicateTrg on Account (before insert,before update)
{
Map<string,Account> accMap = new Map<string,Account>();
set<string> accSet = new set<string>();
    for(Account acc : Trigger.new)
        accSet.add(acc.name);
    for(Account a : [select id,name from Account where name in : accSet])
        accMap.put(a.name,a);
    for(Account acc1 : trigger.new)
        {
        if(accMap.containskey(acc1.name))
           if(Trigger.isInsert){
             acc1.addError('There is another account in the system with this exact name and is a likely duplicate');
           }
           else if(Trigger.isUpdate){
               acc1.addError('There is another Account with the same name as this one. Please navigate to the Account tab');
           
           }
        }
  }

How to apply below senario above trigger updation time

I created a check box named "displayerror". Now in trigger if this check box is true, then throw the error. If check box is false then save the record and have the default value for this check box as true.So when user gets this error he can know the existence of a duplicate account and then in order to save the account he can uncheck the check box which inturn will save the record.

please help me...