• Sebastian Davis
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

Heya,

My code has no error on compilation but when it came to addError, it didn't work when I gave it a try.. here's my code, tell me what's jiffy in it.

 

trigger ErrorDuplicateOutput on Account (before insert, before update)
{
  List<Account> accList =new List<Account>();
  Set<String> b = new Set<String>{'Express Logistics and Transport','Edge Communications'};
  accList = [Select Id, Name FROM Account Where Name in: b];
  
  for (Account acc : accList)
  {
   if (b.contains(acc.Name))
   {
    acc.Name.addError('Account name already exist!');
   }
  }
  update accList;
}

 Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger ErrorDuplicateOutput caused an unexpected exception, contact your administrator: ErrorDuplicateOutput: execution of BeforeInsert caused by: System.FinalException: SObject row does not allow errors: Trigger.ErrorDuplicateOutput: line 11, column 5