fflib-apex-common icon indicating copy to clipboard operation
fflib-apex-common copied to clipboard

Trigger Error Handling

Open tmowbrey opened this issue 9 years ago • 1 comments
trafficstars

Hello,

When writing a trigger and completing a try catch for my DML I would do something similar to the following:

            Map<Id, Account> accounts = new Map<Id, Account>((List<Account>) Records);

            try
            {
                update onlyTheAccountsIWantToUpdate;
            }
            catch(DmlException dmlException)
            {
                for (Integer i = 0; i < dmlException.getNumDml(); i++)
                {
                    Account acc = accounts.get(dmlException.getDmlId(i));
                    acc.addError(dmlException.getDmlMessage(i));
                }
            }

I do this to remove all the stacktrace details so that a more user friendly error message can be displayed to the user (such as when declarative validations are hit).

Currently in this library I am unable (or not sure how to) do this. Can someone please let me know if this is an enhancement or if it is already possible to do?

Thanks! Tyler

tmowbrey avatar Jul 20 '16 17:07 tmowbrey

If this is in a Domain layer class (which among other things, implements the trigger handlers), then take a look at this post where I had a related issue on processing the error message. In the link, you would enhance my verror(...) method to cleanse the exception message of noise-not relevant to the user.

In my orgs, I remove the text 'FIELD_CUSTOM_VALIDATION_EXCEPTION,' and strip out the stack trace except for certain exceptions where I prefer it surfaces right away to aid in diagnostic response time

cropredy avatar Jul 20 '16 18:07 cropredy