2

I need to prevent deletion of our dummy account, which is part of the Lead conversion process under certain conditions. And it does prevent deletion. However, the error I am adding to the account record does not bubble up to the UI.

Am I doing something wrong or is this an expected behavior? Do I need to move my code to "isUpdate" and check the "IsDeleted" flag instead?

Code:

if (Trigger.isBefore) {
    // Prevent dummy account deletion
    if (Trigger.isDelete) {
        for (Account a : Trigger.new) {
            if (a.Name == 'DO NOT DELETE') a.addError('This account may not be deleted. It is part of the Lead conversion process.');
        }
    }

Actual error:

There's a problem saving this record. You might not have permission to edit it, or it might have been deleted or archived. Contact your administrator for help.

1 Answer 1

5

You will need to use Trigger.old in case of delete operation to be able to display your custom error message. This is from the Trigger Exceptions documentation (emphasis mine):

Triggers can be used to prevent DML operations from occurring by calling the addError() method on a record or field. When used on Trigger.new records in insert and update triggers, and on Trigger.old records in delete triggers, the custom error message is displayed in the application interface and logged.

You must log in to answer this question.

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