i want to give link to the record in an error message which i am sending from trigger.


ERROR: An open opportunity <a href='https://bonial3-dev-ed.my.salesforce.com/0065i000006VOl0AAG'>Dickenson Mobile Generators</a> already exist, please close it first before creating new.


String url = URL.getOrgDomainUrl().toExternalForm()+'/'+opportunityList[0].Id;
opp.addError('ERROR: An open opportunity <a href=\''+url+'\'>'+opportunityList[0].Name+'</a> already exist, please close it first before creating new.',false);

I have tried almost all the soln given on :

how to add email id as hyperlink in trigger error message?


How to display a error message with hyperlink on standard detail page through trigger



update: found one thing this code is working in classic but not in lightning.

1 Answer 1


According to the documentation for the SObject addError method you can't escape html in Lightning. If this code has to run in a trigger then I guess you're out of luck.

public Void addError(String errorMsg, Boolean escape)

Escape, Type: Boolean
Indicates whether any HTML markup in the custom error message should be escaped (true) or not (false). This parameter is ignored in both Lightning Experience and the Salesforce mobile app, and the HTML is always escaped. The escape parameter only applies in Salesforce Classic.

  • so there is no workaround to achieve this? Commented Jul 2, 2022 at 10:16
  • @AdityaSahu I'm afraid not
    – Kasper
    Commented Jul 2, 2022 at 15:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .