Can any one help me out .I shall appreciate your help.

I have a two triggers running on my Requirement as 1) Create a case with Subject line (User ) ----First Case

2) Create another case with Same Subject line [either by (Same user or different user )] .----Second Case

3)Now System should automatically identify it as a " Duplicate case and close the case " (i.e second case) .

4)Now the Case Comments of the Closed case (i.e second case) should be added to the existing case ( i.e first case) which is open.

For one of the trigger i have written a Test Class , but the code coverage is None .Dont know where i'm loosing the loop.Thanks in Advance

Trigger 1 :

trigger Case_DuplicateClose on Case (before insert) {
Map<String, Case> newCaseMap = new Map<String, Case>();
for(Case c : trigger.new)
    while(c.Subject.startsWith('RE:') || c.Subject.startsWith('FW:')|| c.Subject.startsWith('Fw:')|| c.Subject.startsWith('Re:'))

        c.Subject = c.Subject.substring(3).trim();
        c.Status = 'Closed';
        newCaseMap.put(c.Subject, c);
for(Case c : [Select Subject From Case Where Subject in :newCaseMap.keySet()])
    newCaseMap.get(c.Subject).status = 'Closed';

Test Class For Trigger 1 :

public class TestCase_DuplicateClose{

 static testmethod void testCaseDuplicate(){

list<Case> cases = new list<case>();

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

Case c = new Case(Subject = 'Test Case' + i);

c.Status = 'closed';



insert cases ;


list<Case> insertedCases = [Select Subject , Status,Origin from case where Id In :cases];

for(Case c :insertedCases)
  • Do you have any validations? Did you supply all the mandatory fields?
    – Vignex
    Commented Nov 5, 2014 at 9:57
  • @vignex:Thanks for your reply.Their are no validation rules, checked in Apex test Execution :it gives an error as :TestCase_DuplicateClosetestCaseDuplicateFailSystem.AssertException: Assertion Failed: Expected: closed, Actual: ClosedClass.TestCase_DuplicateClose.testCaseDuplicate
    – nikkey
    Commented Nov 5, 2014 at 10:01
  • I think you are missing the braces {} after the While condition. It should be IF (instead of While) condition and It should enclose If Else block following!
    – Vignex
    Commented Nov 5, 2014 at 10:02
  • Can you remove Trigger 2 from your description as this is not relevant I suppose!
    – Vignex
    Commented Nov 5, 2014 at 10:09
  • @Vignex:My trigger were used on the requirement ,where i need to use While stmts
    – nikkey
    Commented Nov 5, 2014 at 11:29

1 Answer 1


According to the comments I read, the reason your test coverage is 0 is very simply: the test case fails. And the reason it fails is because you set the status to be 'Closed' in your trigger and 'closed' in your test case. String comparison is case sensitive.

Also, I think there is an error in your trigger 1 as well. It seems to me you are setting every case' status into 'Closed' in your trigger. I bet you are not meant to do this.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .