function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AbAb 

adding error messages to multiple records

Hello,

If i need to add errors to multiple objects that caused the eror.

I am executing triggers and i add apex.add message

but i want to add the message to the multiple objects that created the error

how cna i achieve ot ?

 
Best Answer chosen by Ab
Lalit Mistry 21Lalit Mistry 21
Hi Sandrine,
Assuming you want to have trigger on contact object, you can a trigger like below
trigger ContactTrigger on Contact(before insert)
{
	for(Contact cnt : Trigger.new){
		if(/*check for error condition*/) {
			cnt.addError('Error message');
		}
	}
}

Similarly you can work it out for an object of your interest.