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
RubenjRubenj 

Trigger exception formatting

Hi,

 

I'm trying to have a trigger do some validation upon insert and if some rules are not met then an error is displayed to the user and the data is not stored.  My problem is with the display formatting.  I'm trying to display something like:

 

Message 1

 

Message 2

 

To do so I have a block of code like:

 

string error_message = message1 + '\n\n' + message2;

f.addError(error_message);

return ;

 

The problem I'm facing is that I use this approach on two different objects an in one case it displays like I want it to and in another case it renders as "Message 1<br><br>Message 2".

 

Is there a particular way I have to format my error message to get the rendering to display properly?

 

Thanks,

Ruben

Prakash@SFDCPrakash@SFDC

Try like this 

 

string error_message = message1 + '\n + \n' + message2;

Bhawani SharmaBhawani Sharma
Use <BR/><BR/>
RubenjRubenj

Unfortunately this hasn't resolved the issue.  It still behaves the same way as before.

RubenjRubenj

Html tags are not accepted in the formatting.  When I try to use something like <br/> <br/> this is just displayed instead of any sort of actual formatting of my text.  So it basically renders the <br/> tags along with my messages.

Bhawani SharmaBhawani Sharma
Did you try with?
f.addError(message1);
f.addError(message2);
Prakash@SFDCPrakash@SFDC

This should work .

 

string error_message = message1 + '<br/>' + '<br/>' + message2;

RubenjRubenj

Unfortunately multiple calls to the addError only serves to clear out the previous value.  So in the case of calling addError twice only the second portion of the message is actually displayed.

 

I guess I'm going to just have to redesign the error message display it as one line of text.