How to resolve the adderror in trigger?
I am trying to display an error message if a field on Quote is updated to a certain value. I am doing it on before update but I am encountering an error
Here is a sample code block I am trying on my org
You need to adderror in Trigger.new or Trigger.newMap, unless you're in a delete trigger, in which case you use Trigger.old or Trigger.oldMap.
Given your code, you can get the record from the Trigger.newMap variable:
// Or, ideally, pass in Trigger.newMap as well.
Map newQuotesById = new Map(quotes);
if(arv.contains(bc)) {
newQuotesById.get(q.Id).addError('Error');
}