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
nothingisreal68nothingisreal68 

Add a message to an sObject via a trigger.

Hola,

 

I want to add a message to an sObject via a trigger, to provide some visualfeed back to users upon a save of a page.

 

The standard method addMessage() will not work because it prevents all dml from occuring - something I DONT want to have happen - I still want the record to save.

 

I also played with the visualforce method ApexPages.addMessage() - but this throws a runtime System.Final exception, because it is not being invoked in the context of a visualforce page. 

 

How can I add a message to the top of a page (be it the red error text, or a PageMessage) with a trigger while still saving the object?

 

Thanks in advance. 

nothingisreal68nothingisreal68

Also - this is a standard page, not a custom visualforce page. 

Starz26Starz26

Without a custom visualforce solution, the closest you could come is adding a message field to the object and the page layout. Then using a trigger, update that field as appropriate and make it visible on detail only.

 

The big drawback is the message will always be stored with the record so everytime one would view the record, the message would be there unless the user edited the record and the edit trigger modified the message.

nothingisreal68nothingisreal68

While that is a good idea, it doesn't provide the same level of visual feedback that a message above the detail sections provides, and doesn't follow the standard error displaying convention used through SFDC. Thanks for the suggestion, though.