Prevent Deletion of Active Accounts

This trigger prevents users from deleting Account records marked as “Active” with the value “Yes,” ensuring critical data integrity.

Learn more from this YouTube playlist.

Solution:
trigger AccountTrigger on Account (before delete)
              { if(Trigger.isDelete){ if(Trigger.isBefore){
                                       AccountTriggerHandle.preventDel(Trigger.old);
                           }
            }
}
public class AccountTriggerHandle{ public static void
            preventDel(List<Account> accList){ for(Account acc : accList){ if(acc.Active__c == ‘Yes’){
                 acc.addError(Label.Prevent_Account_Deletion);
                                              }
                               }
                 }
}

Want to Apply As Content Writer?

Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Cart

Let's get you started!

Interested in writing Salesforce Content?

Fill in this form and we will get in touch with you :)