You need to sign in to do that
Don't have an account?
![Yogesh Biyani Yogesh Biyani](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
test class to prevent deletion
I am writing a trigger to prevent detetion of certain accounts
trigger doNotDelete on Account (before delete) { // Prevent the deletion of accounts if it is a customer for (Account a : Trigger.old) { if(a.Customer_ID__c!=NULL) a.adderror('Cannot delete Active Account!'); } }How do I write a test class to this success of the trigger?
@isTest public class doNotDeleteTest { @isTest public static void deleteTest() { Account a =new Account(Name='Test'); a.Customer_ID__c =1234; insert a; try { delete a; } catch (Exception e) { System.debug(e.getTypeName()); System.debug(e.getMessage()); } finally { // Something executed whether there was an error or not } } }
All Answers