• #15032
    Salesforce | PRANAV PRANAV #1

    How to add error message in a Salesforce Apex Trigger?

    Hi All,

    How to add error message in apex trigger ?


    Tagged: , , ,

    Salesforce | Abhinav Abhinav #215

    Hi Pranav,

    Test__c trigObj = trigger.newMap.get(Test.id);
    if(trigObj != null){
    trigObj.addError(‘Cloned record should not have the same period as that of Parent record’);

    Salesforce | shariq shariq #187

    Hi Pranav,

    Yes you can add error messages in triggers by using Salesforce trigger addError method.
    For Example – Sobject.addError(‘Error Messages’);

    • This reply was modified 9 months, 1 week ago by Salesforce | shariq shariq.
     Ratnakar #10

    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL,’Enter Your error message here’));

    Salesforce | PRANAV PRANAV #1

    Hi Ratnakar,

    Whatever you are saying is not correct.

    The solution given by Abhinav is correct and helpful. And the issue resolves previously.

    I appreciate your response if it works for the same but the reply provided by you works for VF page only.


Viewing 5 posts - 1 through 5 (of 5 total)

Please to reply to this topic.


We're not around right now. But you can send us an email and we'll get back to you, asap.


About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2018 Forcetalks. All Right Reserved.

Log in with your credentials


Forgot your details?