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

need test class...code in orange is not covered...plz help
trigger code:
trigger EB_Case_Owner_Trigger on Case (after insert, before update)
{
public EB_SB_Builder__c EB_account {get; private set;}
public RecordType rtype {get; private set;}
integer icount;
String xd12,xd13;
icount = 0;
ID related_to_id, Owner_Id;
Set<Id> tasksInSet = new Set<Id> {};
if (Trigger.isInsert)
{
for (Case t : Trigger.new)
{
tasksInSet.add(t.Id);
icount = icount +1;
}
}
if (Trigger.isUpdate)
{
for (Case t : Trigger.new)
{
tasksInSet.add(t.Id);
icount = icount +1;
}
}
if (icount<=1)
{
if (Trigger.isInsert)
{
Case[] accs;
accs = Trigger.new;
for (Case a:accs){
Date myDate = Date.Today();
Owner_Id = a.OwnerId;
String Case_Sub = a.Subject;
String Case_Desc = a.Description;
String contact_id = a.ContactId;
String Record_type_id = a.RecordTypeId;
rtype = [Select r.Name, r.Id, r.Description From RecordType r where r.Id =:Record_type_id];
xd12= rtype.Description+'';
xd13= xd12.substring(0,3);
if (xd13 == '005')
{
if (contact_id != null)
{
Integer j = [Select count() from RecordType r where r.Id =:Record_type_id];
if(j==1)
{
for (Case tmp : [Select e.Event_Survey_Builder__c, e.OwnerId From Case e where e.id = :a.id limit 1]) {
tmp.OwnerId = rtype.Description;
tmp.Description = xd12;
update tmp;
}
}
Integer i = [select count() from EB_SB_Builder__c EB_SB where EB_SB.Contact__c = :contact_id and EB_SB.OwnerId = :rtype.Description];
if(i==1)
{
EB_account = [select tmp2.Id from EB_SB_Builder__c tmp2 where tmp2.Contact__c = :contact_id and tmp2.OwnerId = :rtype.Description limit 1];
for (Case tmp : [Select e.Event_Survey_Builder__c, e.OwnerId From Case e where e.id = :a.id limit 1]) {
tmp.Event_Survey_Builder__c = EB_account.id;
tmp.OwnerId = rtype.Description;
update tmp;
}
}
}
Task ecs = new Task(Description= Case_Desc, Subject=Case_Sub, ActivityDate=myDate,Status ='Not Started', OwnerId=rtype.Description, WhatId=a.Id);
insert ecs;
icount = icount +1;
}
}
}
}
}
test class:
@isTest(SeeAllData=true)
private class EB_Case_Owner_Trigger_Test_Class {
static testMethod void myUnitTest() {
// TO DO: implement unit test
EB_SB_Builder__c ebsb = new EB_SB_Builder__c ();
Case accs1 = new Case();
insert ebsb;
Datetime dt = Datetime.now();
Case accs = new Case(RecordTypeId='0120000000098Po',Event_Survey_Builder__c = ebsb.Id, Origin= 'Email', Subject='Testing Task', Minutesoncase__c =10, Reason='508 compliance', Product_Type__c = 'Event Tool');
Subject='Testing Task', Minutesoncase__c =10, Reason='508 compliance', Product_Type__c = 'Event Tool' , AccountId='001P000000GF1fq');
insert accs;
}
in your test class
you should satisfy
EB_SB.Contact__c = :contact_id and EB_SB.OwnerId = :rtype.Description
the above conditions.
in your Test class insert fields with as you mentioned like above conditions
prem
Thanks for ur reply Prem...but still it is not covered...here is the test class....
@isTest(SeeAllData=true)
private class EB_Case_Owner_Trigger_Test_Class {
static testMethod void myUnitTest() {
// TO DO: implement unit test
Account acc = new Account();
acc.name = 'Test';
insert acc;
Recordtype rr = new Recordtype();
Contact con = new Contact();
con.LastName = 'Test Contact';
con.AccountId = acc.Id;
insert con;
EB_SB_Builder__c ebsb = new EB_SB_Builder__c ();
ebsb.Project__c = 'abc';
ebsb.Project_Stage__c = 'Started';
ebsb.Project_Type_del__c = 'DE';
ebsb.Project_Complexity__c = 'def';
ebsb.Expected_Launch_Date__c = Date.newInstance(2013,26,3);
ebsb.contact__c = con.id;
ebsb.OwnerId = rr.Description;
insert ebsb;
Datetime dt = Datetime.now();
Case accs = new Case(RecordTypeId='0120000000098Po',Event_Survey_Builder__c = ebsb.Id, Type = 'www',Status = 'open', Origin= 'Email', Subject= 'Testing Task', Minutesoncase__c =10, Reason='508 compliance', Product_Type__c = 'Event Tool');
insert accs;
}
}
If you want you can use the UserId
Like this
ebsb.OwnerId = userinfo.getUserID();
Use System.Debug in your Trigger
Run a Test class .
Integer i = [select count() from EB_SB_Builder__c EB_SB where EB_SB.Contact__c = :contact_id and EB_SB.OwnerId = :rtype.Description];
System.Debug('*************test class*****'+i);
if(i==1)
{ ---- ----
}
Check in Developer console .What is i value..
wether it is 0 or 1 or more that one.
Based on that you need to change your Test class
Prem