You need to sign in to do that
Don't have an account?

Test Class
I have a trigger that was updated to handle bulk case closures and it works but when i deploy to production i get errors from other test classes what have nothing to do with my trigger. So i think i need to have a test created but am having trouble to create one. Here is the trigger i have created.
trigger pullSE on Case (before update, before insert) { Set<id> userids=new Set<id>(); Map<id,string> siteMap=new Map<id,string>(); for (case t: trigger.new) { try { if (t.SE__c == null) { userids.add(t.site__c); } } catch (Exception e) { } } if(userids!=null){ for(site__c s:[select id,user__c from site__c where id in:userids]){ siteMap.put(s.id,s.user__c); } } for(case t:trigger.new){ t.se__c=sitemap.get(t.site__c); } }
Hi,
Try the following test class,
@isTest(SeeAllData == true)
public class Test_pullSE_Trigger{
public static testMethod void test1(){
user u = [select id,name from user where id = UserInfo.getUserId() limit 1];
Site__c s = new Site__c(name = 'test', user__c = u.id);
insert s;
Case c = new Case(Origin = 'Phone', Status = 'New', SE__c = null, site__c = s.id);
insert c;
c.SE__c = s.user__c;
update c;
}
}
Hope so this helps you...!
Please mark this answer a Solution and please give kudos by clicking on the star icon, if you found this answer as helpful.
Thanks Kamatchi for the help, however i am getting an error message that says ( Unexpected token: 'Userinfo.getUserID' )
Hi,
Sorry i missed a colon in the checking part.
Try the following test class,
@isTest(SeeAllData == true)
public class Test_pullSE_Trigger{
public static testMethod void test1(){
user u = [select id,name from user where id = : UserInfo.getUserId() limit 1];
Site__c s = new Site__c(name = 'test', user__c = u.id);
insert s;
Case c = new Case(Origin = 'Phone', Status = 'New', SE__c = null, site__c = s.id);
insert c;
c.SE__c = s.user__c;
update c;
}
}
Hope so this helps you...!
Please mark this answer a Solution and please give kudos by clicking on the star icon, if you found this answer as helpful.