+ Start a Discussion
JNicJNic 

Hyperlink in a Trigger Error Messages

Hey guys, Can you provide a hyperlink or a link to a URL through a Error message displayed as part of a Trigger? For example, instead of hardcoding the URL as shown below, use a markup to make it a link: c.addError('ERROR TRM100: There is already an identical record: Record Number '+cs.Number+' (https://na8.salesforce.com/'+cs.Id+')'); This currently reads as: Error: Invalid Data. Review all error messages below to correct your data. ERROR TRM100: There is already an identical record: Record Number 60311 (https://na8.salesforce.com/500M0000000mJJ9IAM) It would be great if I could make the "Record Number 60311" a hyperlink. Any idea is greatly appreciated. Thanks,
Best Answer chosen by Admin (Salesforce Developers) 
vhanson222vhanson222

I assume you could just add some basic html in to your error message:

 

 

c.addError('ERROR TRM100: There is already an identical record: <a href=\'https://na8.salesforce.com/' + cs.Number + '\'>Record Number ' + cs.Number + '</a>';

 

 

Also make sure that in the <apex:pageMessages> element that you specify escape="false".

 

 

<apex:pageMessages id="errMessages" escape="false" />

 

 

Hope that helps.

 

-Victor

All Answers

vhanson222vhanson222

I assume you could just add some basic html in to your error message:

 

 

c.addError('ERROR TRM100: There is already an identical record: <a href=\'https://na8.salesforce.com/' + cs.Number + '\'>Record Number ' + cs.Number + '</a>';

 

 

Also make sure that in the <apex:pageMessages> element that you specify escape="false".

 

 

<apex:pageMessages id="errMessages" escape="false" />

 

 

Hope that helps.

 

-Victor

This was selected as the best answer
JNicJNic

Thank you Victor,

 

 

The simple html markup wortiked.  However when I added some styling attribute to it (style=color:1B2BE0) the coloring that I was looking for only displayed correct at Trigger.IsUpdate.  When addError was executed on Insert of the record, the correct color was not displayed.

 

Do you know why the correct color is not being displayed on Insert of the record? Here is the code that I used:

c.addError('ERROR TRM100: There is already an identical record: <a style=color:1B2BE0 href=\'https://na8.salesforce.com/' + cs.Number + '\'>Record Number ' + cs.Number + '</a>';
vhanson222vhanson222

it looks like you just forgot to add the parentheses around the style attribute.

 

The code below should work:

 

 

c.addError('ERROR TRM100: There is already an identical record: <a style=\'color:1B2BE0\' href=\'https://na8.salesforce.com/' + cs.Number + '\'>Record Number ' + cs.Number + '</a>';

 

JNicJNic

The hyperlink works fine but after adding the '' per above, the hyperlink color was black by default.

The link works and is intuitive enough.

 

Thank you,

YasirYasir

thnx vhanson222 its save my tym and working awesome 

very helpful

metaforcemetaforce

hey vhanson222, any idea if we can display this error message with a hyperlink on the salesforce standard UI instead of a visualforce page? I tried but in vain, it simply displays html markup as plain text in the error message!

JPlayEHRJPlayEHR

Aren't you missing a ')' at the end of the line before the semi-colon?