Salesforce | Display error message returned by Trigger with enter key

Author - Kiranpreet Kaur
16.01.2018
|
5 Comments
|

How to send an error message from trigger back to the layout and display it on the record detail page. You need to use addError method for this.

For example :

errorMsg=’Some of the catalog courses are not available in LMS.<br/>Please sync them to LMS first’;
for( Account account: trigger.new ){
   account.addError(errorMsg);
}

It will show on the top of the page as :

1

But we also need to add new line character to this message. For this, you need to add in the message and send extra parameter in the addError method like :

errorMsg=’Some of the catalog courses are not available in LMS.<br/>Please sync them to LMS first’;
for( Account account: trigger.new ){
   account.addError(errorMsg,false);
}

Now it will look like this :

2

Webner Solutions is a Software Development company focused on developing Insurance Agency Management Systems, Learning Management Systems and Salesforce apps. Contact us at dev@webners.com for your Insurance, eLearning and Salesforce applications.

5 responses on “Salesforce | Display error message returned by Trigger with enter key

  1. Pulkit says:

    This is not working, everywhere I see this addError() but not working.

  2. Chai says:

    It helped, Thanks. But we show the error on top of the field instead of showing it on the top of the page.

    • Chai says:

      But, Can we* show the error on top of the field? instead of showing it on the top of the page.

      • Webner says:

        Yes, it is possible. You will have to add error on the specific field.
        For example, Trigger.new[0].myField__c.addError(‘badvalue’);
        In the above example, add error as “account.customField__c.addError(‘Error Message’);”

Leave a Reply

Your email address will not be published. Required fields are marked *