Wednesday, 10 October 2018


Trigger to prevent creation of duplicate accounts


trigger AccountDuplicateTrigger on Account (before update) {
//For fetching existing account names
     map<Id,Account> existingAccountMap = new  map<Id,Account>([Select Id, Name, Rating From Account]);
 for(Account a : Trigger.new){
        if(a.name = existingAccountMap.get(a.Id).Name){
          a.adderror('You cannot create a dulplicate account');
        }
     }
}