问题为触发器创建测试类

时间:2014-10-03 13:05:22

标签: class triggers salesforce apex-code apex

我无法为我创建的触发器创建测试类。触发器每隔一段时间更新一个日期/时间字段,修改复选框字段。我不确定如何创建测试触发器,任何帮助都会很棒。

我的触发器是:

 trigger ControlRoomCheckedTimeTrigger on Match_Day_Check_List__c (before insert, before update) {
        if(Trigger.isInsert){
         for(match_day_check_list__c b: trigger.new){
          b.Steward_Phone_Check_Complete_Last_Mod__c = DateTime.Now();
          b.Radio_Check_Complete_Last_Modified__c = DateTime.Now();
          b.CCTV_Cameras_Checked_Last_Modified__c = DateTime.Now();
        }
      }
      if(Trigger.isUpdate){
            for(match_day_check_list__c b: trigger.new){
                match_day_check_list__c oldb = Trigger.oldMap.get(b.ID);

                if(oldb.Steward_Phone_Check_Complete__c != b.Steward_Phone_Check_Complete__c){
                    b.Steward_Phone_Check_Complete_Last_Mod__c = DateTime.Now();
                }
                if(oldb.Radio_Check_Complete__c != b.Radio_Check_Complete__c){

                    b.Radio_Check_Complete_Last_Modified__c = DateTime.Now();

                }


                if(oldb.CCTV_Cameras_Checked__c != b.CCTV_Cameras_Checked__c){
                    b.CCTV_Cameras_Checked_Last_Modified__c = DateTime.Now();
                }

                if(oldb.Turnstile_Checks_Control_Room__c != b.Turnstile_Checks_Control_Room__c){
                    b.Turnstile_Checks_Last_Modified_CRoom__c = DateTime.Now();
                }
        }
    }
    }

Many Thanks

1 个答案:

答案 0 :(得分:0)

@isTest
public class TestClass {

  @isTest
  static void firstTest() {
    Match_Day_Check_List__c mdcl01 = new Match_Day_Check_List__c(
      // put mandatory fields here
    );
    insert mdcl01; // check insert logic

    mdcl01.Steward_Phone_Check_Complete__c = !mdcl01.Steward_Phone_Check_Complete__c;
    mdcl01.Radio_Check_Complete__c = !mdcl01.Radio_Check_Complete__c;
    mdcl01.CCTV_Cameras_Checked__c = !mdcl01.CCTV_Cameras_Checked__c;
    mdcl01.Turnstile_Checks_Control_Room__c = !mdcl01.Turnstile_Checks_Control_Room__c;
    update mdcl01; // check update logic 
  }
}