• Joseph Minik
  • NEWBIE
  • 25 Points
  • Member since 2020
  • Senior Software Engineer


  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
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
        }
        
    }
}
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
        }
        
    }
}

Is there any method to get user timezone in apex class.