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
hmoh1920hmoh1920 

custom error message for try{}catch

Hi,

 

I like add an custom error message for my trigger into try{}catch....

 

please how?

 

 

thanks.

 

 

 

M.H

 

 

Navatar_DbSupNavatar_DbSup

Hi,


You can use the addError() method for displaying the custom error in the trigger.

 

Use the below code as reference

try
{
update accounts;
}
catch (DMLException e)
{
for (Account account : accounts)
{
account.addError('There was a problem updating the accounts');
}
}

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.