You need to sign in to do that
Don't have an account?
nikkey
Test Class Code coverage for a trigger is 70% and Error as :Only top-level class methods can be declared static
Can any one help on this .I have a trigger written on Case object for the duplication to get it closed .I have written a Test class where it gives the code coverage as 70% only. When i Execute in Developer Console it throws an Error as :
Test Class :
Any help very much appreciated.
Line: 3, Column: 24 Only top-level class methods can be declared staticTrigger :
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('Re:') || c.Subject.startsWith('FW:') || c.Subject.startsWith('Fw:')) c.Subject = c.Subject.substring(3).trim(); if(newCaseMap.containsKey(c.Subject)) c.Status = 'Closed'; else 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 :
@istest private 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='RE:'+i); cases.add(c); } test.startTest(); insert cases; test.stopTest(); List<case> insertedcases =[Select Subject,status from case where id in:cases]; for(case c :insertedcases){ system.assertEquals( 'Closed',c.status); } } }
Any help very much appreciated.
@istest
private 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='RE:'+i, Status = 'Closed');
cases.add(c);
}
test.startTest();
insert cases;
test.stopTest();
List<case> insertedcases =[Select Subject,status from case where id in:cases];
for(case c :insertedcases){
system.assertEquals(
'Closed',c.status);
}
}
}