I have added a validation in Account Trigger to prevent the deletion of Account record if the status is other than Archived

for(Account objAccount: lstOldAccount){
    if(objAccount.Status__c != 'Archived'){
      objAccount.addError('<h1 style="color:red;">You can not delete an account with live status.</h1>', false);

So When I try to delete an account with active status is show the error with html formatted

enter image description here

But when you go back to lighting Experience and try to delete the same record with active status

It shows the HTML code and escape=false doesn't work it seems

enter image description here

is it a Salesforce bug?


See the idea HTML tags in the error message are escaped even if escape = false is specified at sObject.addError() in Lightning UI and Salesforce1

Sounds like they aren't going to fix/change it.

This limitation has been documented at https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_sobject.htm#apex_System_SObject_field_addError.

From the linked addError(errorMsg, escape) docs:

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

| improve this answer | |
  • 2
    Ahh, I missed the documentation part somehow. Thanks – Ratan Paul Jul 19 '18 at 11:50

While Salesforce fixes the bug, you can use the below workaround.

I created a dummy trigger to see what request URL we get in classic and Salesforce.

trigger ProofTrigger on Proof__c (after insert, after update) {


When in classic the Debug I get


whereas in Lightning the debug I get is


So you can write an if-else to use the following feature to your advantage.

for(Account objAccount: lstOldAccount){

    if(objAccount.Status__c != 'Archived'){ // This is classic
        objAccount.addError('<h1 style="color:red;">You can not delete an account with live status.</h1>', false);
      }else{ // This is lightning
        objAccount.addError('You can not delete an account with live status.');

| improve this answer | |
  • Thanks, man for the solution, But I was looking why it is not working. – Ratan Paul Jul 19 '18 at 11:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.