2014-03-12 59 views
-1

我需要爲以下觸發器編寫測試類,以便我可以增加測試共享,以便在salesforce上上傳包。我不知道如何編寫觸發器的測試類。需要爲銷售隊伍觸發測試共享類

Trigger AutoActivityCreation on Account(after update) 
{ 

    List<Task> task = new List<Task>(); 

for (Integer i = 0; i < Trigger.new.size(); i++) { 

         List<String> techs = Trigger.new[i].Toolsberry_new_tech_installs__c.split(';');      
         Integer added_tech = techs.size(); 

         if(Trigger.new[i].Toolsberry_new_tech_installs__c=='null'){ 
          added_tech=0; 
         } 

         List<String> re_techs = Trigger.new[i].Toolsberry_removed_tech_installs__c.split(';'); 
         Integer removed_tech = re_techs.size(); 

         if(Trigger.new[i].Toolsberry_removed_tech_installs__c=='null'){ 
          removed_tech=0; 
         } 


task.add(new Task(
         whatid=Trigger.new[i].Id, 
         OwnerId=Trigger.new[i].OwnerId, 
         Subject='Technologies Added '+added_tech+' , Removed '+removed_tech, 
         Status = 'Completed', 
         ActivityDate = system.today() 
         )) ; 
} 

insert task; 

} 

can anybody help for this how to write test covrage class. 

Thanks 
Rajendra J. 

回答

0

請檢查它是否適用於您。

@isTest 
private class TriggerTestClass { 

    static testMethod void autoTasktest() { 
     // TO DO: implement unit test 

     Account acc = new Account(
     Name = 'Test Account 1', 
     Phone = '07123123123', 
     Toolsberry_new_tech_installs__c = 'null', 
     Toolsberry_removed_tech_installs__c = 'null'); 
     insert acc; 

     acc.BillingCity = 'Test Area 2'; 
     update acc; 


    } 
} 

並確保您在您的測試方法中添加了帳戶對象中所需的值的字段。它會給你最好的報道。