+ Start a Discussion
MILKMILK 

Help writing a test class for my trigger!!thanks!!!!!

trigger AccountEntitlementUsedTrigger on Account_Entitlement_Used__c (after delete, after insert, after update) {
  if(Trigger.isDelete){
    List<id> LAcctID = new List<id>();
    for(Account_Entitlement_Used__c AE : Trigger.old){
      LAcctID.add(AE.Customer_Name__c);
    }
    List<Account> LAcctUpd = new List<Account>();
    for(Account Acct : [Select id, Current_Balance_CRA__c, Current_Balance_Miele__c, Current_Balance_Partner__c,Total_Partner_Event_Balance__c, Total_Miele_Event_Balance__c,Total_CRA_Balance__c
      from Account where id IN :LAcctID]){
     Acct.Current_Balance_Partner__c = BenefitCalculation.countEntitlementNumber(Acct.id,'Partner Events', date.today())[3];
     Acct.Current_Balance_Miele__c = BenefitCalculation.countEntitlementNumber(Acct.id,'Miele Events', date.today())[3];
      Acct.Current_Balance_CRA__c = BenefitCalculation.countEntitlementNumber(Acct.id,'CRA Services', date.today())[3];
         
       
    //List<String> LType = new String[]{'CRA Services','Miele Events','Partner Events'};
     //  List<integer> HType = new integer[]{0,0,0};
     //  for(Integer i = 0; i < 3; i++){
     //  HType[i]=BenefitCalculation.countEntitlementNumber(Acct.id,LType[i], date.today())[4];
       
       
  //Acct.Total_CRA_Balance__c=HType[0];  
 //Acct.Total_Partner_Event_Balance__c =HType[1];
// Acct.Total_Miele_Event_Balance__c = HType[2];

    //   }
      

  
 

      LAcctUpd.add(Acct);
    }
    if(LAcctUpd != null && LAcctUpd.size()>0)
      update LAcctUpd;
      
      
    //////////////////////////  
      
    List<Account_Entitlement__c> LAcctUpdd = new List<Account_Entitlement__c>();
    for(Account_Entitlement__c Acctt : [Select id from Account_Entitlement__c where id IN :LAcctID]){
      Acctt.Related_Entitlement_Used__c='';
      LAcctUpdd.add(Acctt);
    }
    if(LAcctUpdd != null && LAcctUpdd.size()>0)
      update LAcctUpdd;
  
  }
  else if(Trigger.isUpdate){
    
 List<id> LAcctID = new List<id>();
  for(Account_Entitlement_Used__c AE : Trigger.new){
    LAcctID.add(AE.Customer_Name__c);
  }
 List<Account> LAcctUpd = new List<Account>();
 for(Account Acct : [Select id, Current_Balance_CRA__c, Current_Balance_Miele__c, Current_Balance_Partner__c ,Total_Partner_Event_Balance__c, Total_Miele_Event_Balance__c,Total_CRA_Balance__c
     from Account where id IN :LAcctID]){
   Acct.Current_Balance_Partner__c = BenefitCalculation.countEntitlementNumber(Acct.id,'Partner Events', date.today())[3];
     Acct.Current_Balance_Miele__c = BenefitCalculation.countEntitlementNumber(Acct.id,'Miele Events', date.today())[3];
     Acct.Current_Balance_CRA__c = BenefitCalculation.countEntitlementNumber(Acct.id,'CRA Services', date.today())[3];
           
       
   // List<String> LType = new String[]{'CRA Services','Miele Events','Partner Events'};
     //  List<integer> HType = new integer[]{0,0,0};
     //  for(Integer i = 0; i < 3; i++){
    //   HType[i]=BenefitCalculation.countEntitlementNumber(Acct.id,LType[i], date.today())[4];
       
       
 // Acct.Total_CRA_Balance__c=HType[0];  
 //Acct.Total_Partner_Event_Balance__c =HType[1];
 //Acct.Total_Miele_Event_Balance__c = HType[2];

       //}

      LAcctUpd.add(Acct);
 }
  if(LAcctUpd != null && LAcctUpd.size()>0)
    update LAcctUpd;
    
 }
    else if(Trigger.isInsert){
      string abc;
    Set<String> Sname= new Set<String>();
    List<id> LAcctID = new List<id>();
    for(Account_Entitlement_Used__c AE : Trigger.new){
      LAcctID.add(AE.Customer_Name__c);
      Sname.add(AE.Entitlement_Type__c);
   abc=AE.id;
    }
    

    
    
    List<Account> LAcctUpd = new List<Account>();
    for(Account Acct : [Select id, Current_Balance_CRA__c, Current_Balance_Miele__c, Current_Balance_Partner__c ,Total_CRA_Balance__c,Total_Miele_Event_Balance__c,Total_Partner_Event_Balance__c
      from Account where id IN :LAcctID]){
     Acct.Current_Balance_Partner__c = BenefitCalculation.countEntitlementNumber(Acct.id,'Partner Events', date.today())[3];
      Acct.Current_Balance_Miele__c = BenefitCalculation.countEntitlementNumber(Acct.id,'Miele Events', date.today())[3];
   Acct.Current_Balance_CRA__c = BenefitCalculation.countEntitlementNumber(Acct.id,'CRA Services', date.today())[3];
     
      
       
    //List<String> LType = new String[]{'CRA Services','Miele Events','Partner Events'};
    //   List<integer> HType = new integer[]{0,0,0};
     //  for(Integer i = 0; i < 3; i++){
     //  HType[i]=BenefitCalculation.countEntitlementNumber(Acct.id,LType[i], date.today())[4];
       
       
 // Acct.Total_CRA_Balance__c=HType[0];  
// Acct.Total_Partner_Event_Balance__c =HType[1];
// Acct.Total_Miele_Event_Balance__c = HType[2];

     //  }
      LAcctUpd.add(Acct);
    }
    if(LAcctUpd != null && LAcctUpd.size()>0)
      update LAcctUpd;
      
       
    List<Account_Entitlement__c> LAcctUpdd = new List<Account_Entitlement__c>();
    for(Account_Entitlement__c Acctt : [Select Customer_Name__c from Account_Entitlement__c where Customer_Name__c IN :LAcctID and Expired__c=false and Related_Entitlement_Used__c=null and Entitlement_Type__c IN :Sname  order by Id asc limit 1]){

      
      
        Acctt.Related_Entitlement_Used__c=abc;
        LAcctUpdd.add(Acctt);
   
    }
    if(LAcctUpdd != null && LAcctUpdd.size()>0)
      update LAcctUpdd;
   

      

  }



}

AsitM9AsitM9
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_qs_test.htm

follow the link.
If you stuck any where get back to us,we are always here to help you.