I'm trying to add the record link inside the "addError" on the trigger

for(Account account : (List<Account>) triggerParams.triggerNew) {
      String url = URL.getOrgDomainUrl()+'/'+account.Id;
    account.addError('ERROR:<a href=\''+url+'\'>More details</a>', false);

But the result is this

ERROR:<a href='Url:[delegate=https://myOrg.com]/0016w000007aC6fAAE'>More details</a>

Can someone help me?

1 Answer 1


The getOrgDomainUrl method returns a Url. You need to convert it to a string via toExternalForm:

  String url = URL.getOrgDomainUrl().toExternalForm()+'/'+account.Id;
  • I'm using toecternalform, but it still doesn't seem like the <a> tag is recognized and interpreted as markup. The string is shown literally.
    – Schnaps
    Jul 21, 2022 at 13:24
  • 1
    @Schnaps HTML errors are not supported in Lightning Experience. If you are still using classic, you can use the addError(message, escape) version of the method to specify the HTML should be shown literally. This answer only addresses why the URL appeared incorrectly. See docs
    – sfdcfox
    Jul 21, 2022 at 14:39
  • That's what I was afraid to hear. The way I searched I just wasn't able to get confirmation on that.
    – Schnaps
    Jul 22, 2022 at 5:58

You must log in to answer this question.

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