Skip to main content
meghna m a posé une question dans #Apex
Can any one help me out on this?how to write a Test class for the trigger.Any help is very much appreciated.

Trigger:

 

trigger ReparentComment on CaseComment (before insert) {

Map<String, Case> newCaseMap = new Map<String, Case>();

Set<Id> caseIds = new Set<Id>();

Map<Id, List<CaseComment>> ccMap = new Map<Id, List<CaseComment>>();

List<CaseComment> newCCList = new List<CaseComment>();

for(CaseComment cc : trigger.new)

{

caseIds.add(cc.ParentId);

List<CaseComment> ccList = ccMap.get(cc.ParentId);

if(ccList == null)

ccList = new List<CaseComment>();

ccList.add(cc);

ccMap.put(cc.ParentId, ccList);

}

for(Case c : [Select Id, Subject From Case Where Id in :caseIds Order by CreatedDate])

if(newCaseMap.containsKey(c.Subject))

for(CaseComment cc : ccMap.get(c.Id))

{

CaseComment newCC = cc.clone();

newCCList.add(newCC);

newCC.ParentId = newCaseMap.get(c.Subject).Id;

}

else

newCaseMap.put(c.Subject, c);

for(Case c : [Select Id, Subject From Case Where Subject in :newCaseMap.keySet() And Id not in :caseIds And Status != 'Closed'])

for(CaseComment cc : ccMap.get(newCaseMap.get(c.Subject).Id))

{

CaseComment newCC = cc.clone();

newCCList.add(newCC);

newCC.ParentId = c.Id;

}

insert newCCList;

}

Test Class :

 

@istest

public class TestReparentComment{

static TestMethod void testcomment(){

list<casecomment> ccomment = new list<casecomment>();

for(integer i=0;i<200;i++){

case c= new case(subject='RE:');

insert c

casecomment cc = new casecomment(cc.commentBody = c.Description)

Parentid=c.id;

insert cc;

List<case> insertedcases =[Select Name ,Subject,status from case Where Id in :c.Id Order by CreatedDate];

for(case c :insertedcases){

system.assertEquals(

'NotClosed',c.status);

}

}

}

 
2 réponses
  1. 16 mars 2015, 09:39

    Hi PrakashB ,

    Thanks for your reply.

    The code works fine now ,but when i moved the code into production its showing code coverage as 0% while in Sandbox it is showing as 62%.Will the code work in production now.Any help very much appreciated.

0/9000