1

I am sure my Title does not help much, but not sure how to shorten this question concisely.

I have a Lightning Component that has the ability to update a case record. I have an APEX Trigger that under some rarer conditions will stop that update from happening.

How can I show the thisCase.addError('Blah blah blah') from the Trigger on the Lightning Component? Do I have to try and catch the update statement in my APEX Lightning Controller? I would not think so as I don't see in messages coming through the Dev Console without the Try Catch block.

Editing the Case record directly shows the addError() as expected. Just wondering how to transfer the contents of the addError() to the Lightning Component for display as well.

1 Answer 1

1

Assuming you are invoking the update on your record from Apex Controller, you will need to catch the DMLException and then propagate the exception to your Lightning Aura Component using AuraHandledException.

The code in your apex controller will look something as:

@AuraEnabled
public static String myCaseUpdate(Case c) { 
    ...
    try {
        update c;
    } catch (DMLException dml) {
        throw new AuraHandledException('your exception message');
    }
    ...
}

You can find more details on Returning Errors from an Apex Server-Side Controller

2
  • Bingo! Thank you very much @Jayant !
    – Daniel W
    Jun 14, 2019 at 18:45
  • @DanielW Happy to help. Glad that it worked for you :)
    – Jayant Das
    Jun 14, 2019 at 18:46

You must log in to answer this question.

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