• Holly Havelka
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
Hello all - can someone help me with a very basic trigger and test class?

My Trigger:

trigger LeaveBeforeDelete on VBA_CC_Tracking_Leave_Manager__c (before delete)
{
  for  (VBA_CC_Tracking_Leave_Manager__c q: trigger.old)
  
       if (q.Status_of_Request__c != 'Pending')
               
           {
           
           q.adderror('This record cannot be deleted due to the status being other than "Pending". Thank you');
           
           } 
}

My Test Class:

@IsTest
public class LeaveBeforeDeleteTest {

    static void testLeaveBeforeDelete() {
       
        User u = new User();
        u.FirstName = 'Mr';
        u.LastName = 'Tester';
        u.Email = 'mr.tester@va.gov';
        u.Alias = 'mtest';
        u.Username = 'mr.tester@va.gov';
        u.ProfileID = '00et0000000QGuG';
        
        u.TimezoneSidKey = 'America/Denver';
        u.LocaleSidKey = 'en_US';
        u.EmailEncodingKey = 'UTF-8';
        u.LanguageLocaleKey = 'en_US';
        
        insert u;
        
        system.runAs(u){
    
        VBA_CCTracking_Agent_Production_Data__c a = new VBA_CCTracking_Agent_Production_Data__c();
        a.Name = 'MrTester-2016-05-13';
        a.VBA_CC_Date_of_Data__c = date.newInstance(2016, 5, 13);
        
        insert a;                                        
                       
        VBA_CC_Tracking_Leave_Manager__c b = new VBA_CC_Tracking_Leave_Manager__c();        
        b.Agent_Name_Date__c = a.Id;
        b.Status_of_Request__c = 'Approved';
        
               
        insert b;
           
        try
           {
               Delete a;
               System.assert(true);
            }
           catch(Exception e) 
           {
               system.assertEquals('This record cannot be deleted due to the status being other than "Pending". Thank you', e.getMessage());
            }      
        
        }
                        
        
    }

}
Hello all - can someone help me with a very basic trigger and test class?

My Trigger:

trigger LeaveBeforeDelete on VBA_CC_Tracking_Leave_Manager__c (before delete)
{
  for  (VBA_CC_Tracking_Leave_Manager__c q: trigger.old)
  
       if (q.Status_of_Request__c != 'Pending')
               
           {
           
           q.adderror('This record cannot be deleted due to the status being other than "Pending". Thank you');
           
           } 
}

My Test Class:

@IsTest
public class LeaveBeforeDeleteTest {

    static void testLeaveBeforeDelete() {
       
        User u = new User();
        u.FirstName = 'Mr';
        u.LastName = 'Tester';
        u.Email = 'mr.tester@va.gov';
        u.Alias = 'mtest';
        u.Username = 'mr.tester@va.gov';
        u.ProfileID = '00et0000000QGuG';
        
        u.TimezoneSidKey = 'America/Denver';
        u.LocaleSidKey = 'en_US';
        u.EmailEncodingKey = 'UTF-8';
        u.LanguageLocaleKey = 'en_US';
        
        insert u;
        
        system.runAs(u){
    
        VBA_CCTracking_Agent_Production_Data__c a = new VBA_CCTracking_Agent_Production_Data__c();
        a.Name = 'MrTester-2016-05-13';
        a.VBA_CC_Date_of_Data__c = date.newInstance(2016, 5, 13);
        
        insert a;                                        
                       
        VBA_CC_Tracking_Leave_Manager__c b = new VBA_CC_Tracking_Leave_Manager__c();        
        b.Agent_Name_Date__c = a.Id;
        b.Status_of_Request__c = 'Approved';
        
               
        insert b;
           
        try
           {
               Delete a;
               System.assert(true);
            }
           catch(Exception e) 
           {
               system.assertEquals('This record cannot be deleted due to the status being other than "Pending". Thank you', e.getMessage());
            }      
        
        }
                        
        
    }

}