1

I have a trigger on an object, and in that trigger I am doing the following:

List<ApexPages.Message> msgs = RecordValidator.isValidRecord(thisObj, criteria, matchingObjectUnionList.values());
if (!msgs.isEmpty()) {
    // add messages to page
    for (ApexPages.Message m : msgs) {
        system.debug(m.getDetail());
        thisDef.addError(m.getDetail());
    }
}

I have confirmed in my debug logs that two errors are found for blah 3 and blah each (see image below), so each of those gets two errors added through addError.

However, in the list view for my object when I try to update using inline edit, It gets the two errors according to debug logs, but when I click the red warning sign:

enter image description here

only one of the two is shown...

Is that a known issue with addError in lightning experience? Or how can I make sure it is displaying all errors it adds through addError?

3

It's a limitation of the addError interface. You are allowed at most one record-level error and one field level error per field. Adding a subsequent error will replace the original. This is also not a limit of Lightning, as you will experience the same behavior when using the API or the Classic UI. I don't think this is documented anywhere, but you should be aware of it. Unfortunately, since there's no way to dynamically select a field, you're going to have to come up with a way to add the error(s) to specific fields, or you might just want to join all the errors into a single string, then add them all at once.

if (!msgs.isEmpty()) {
    // add messages to page
    String[] messages = new String[0];
    for (ApexPages.Message m : msgs) {
        messages.add(m.getDetail());
    }
    thisDef.addError(String.join(messages,', '));
}
  • Thanks for the quick reply and easy workaround for this. That will work just fine for us. And the addError limitation is good to know. I figured it was going to be a designed limitation since I was experiencing that behavior, but could not actually find any information on this. Thanks again! – Tyler Dahle Oct 23 '18 at 19:35

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.