I have some trigger logic, which prevents Account to be deleted under specific circumstances. This part works. However when user tries to delete Account via GUI, Salesforce displays really ugly and confusing alert: "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."

It should display exception message instead. From my experience it usually does. Why not in this case? Did I miss some setting? I'll be grateful for any hint or explanation.


                //irrelevant logic                      
                throw new MyCustomInvalidOperationException('You cannot delete Account which has already become a customer and is linked to Navision. You can however change its Status to Former Customer instead');

Why don't you use trigger.addError() instead of custom exception handling

Go through the following example:

eg. Suppose i want to restrict the user from deleting an account, if account has related opportunities

trigger AccountDeletion on Account (before delete) {
//Prevent the deletion of accounts if they have related opportunity.
for (Account a : [SELECT Id FROM Account
                 WHERE Id IN (SELECT AccountId FROM Opportunity) AND
                 Id IN :Trigger.old]){
        'Cannot delete account with related opportunities.');

The same way you can do!


It's nearly impossible to fully answer your question without seeing your trigger code. That being said, my best guess is that the GUI is causing page validation rules to fire which prevents the page from being deleted by the user that are related to the user's permissions. In essence, they don't have CRUD permissions to delete the record.

  • I added short snippet. This code caused break in the trigger run. Simple exception throw. Regarding users right and permissions, when I remove this code, the Account can be deleted without any issues. – Qerts Sep 26 '17 at 12:43

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.