You need to sign in to do that
Don't have an account?
sudhirn@merunetworks.com
Lead test class not getting coverage for trigger
Hi,
I wrote a trigger below which is working fine now I need to get code coverage for below trigger wrote a test class its showing only 64% coverage. what is the misssing the test class
Test Class
Thanks
Sudhir
I wrote a trigger below which is working fine now I need to get code coverage for below trigger wrote a test class its showing only 64% coverage. what is the misssing the test class
trigger after_territory on Lead (after insert,after update) { if(checkRecursive.runOnce()) { Try { Set<Id> leadIds = new Set<Id>(); List<Territory_Lookup__c> territoryLookupList = null; List<Integer> gzip = new List<Integer>(); // we need a list so that we can sort it. Set<String> gstate = new Set<String>(); Set<String> gcountry = new Set<String>(); for(Lead l : Trigger.new){ leadIds.add(l.id); gstate.add(l.state); gcountry.add(l.country); if ( l.postalcode != null) { gzip.add(Integer.valueof(l.postalcode)); } if ( l.postalcode == null) { gzip.add(Integer.valueof(0)); } } if ( trigger.isInsert || trigger.isupdate ) { territoryLookupList = [ select id,Area__c, Country__c, Region__c, State__c, Theater__c, User__c, Zip_End__c, Zip_Start__c from Territory_Lookup__c where ( Country__c = :gcountry) or ( Zip_Start__c <= :gzip and Zip_End__c >=:gzip) or ( Country__c = :gcountry and Zip_Start__c <= :gzip and Zip_End__c >=:gzip ) or ( Country__c = :gcountry and State__c = :gstate) or ( Country__c = :gcountry and Zip_Start__c <= :gzip and Zip_End__c >=:gzip and State__c = :gstate ) ]; List<Lead> leds = new List<Lead>(); if ( !territoryLookupList.isEmpty() ) { for(lead uld : Trigger.new){ lead uleds = new lead( Id = uld.id,Territory_Lookup__c = territoryLookupList[0].id, Territory_Area__c = territoryLookupList[0].Area__c, Territory_Region__c = territoryLookupList[0].Region__c, Territory_Theater__c = territoryLookupList[0].Theater__c); leds.add(uleds); } } else { for(lead uld : Trigger.new){ lead uleds = new lead( Id = uld.id,Territory_Lookup__c = null, Territory_Area__c = null, Territory_Region__c = null, Territory_Theater__c = null); leds.add(uleds); } } if ( leds.size() > 0) { update leds; } } } catch (Exception e) { List<Lead> leds = new List<Lead>(); for(lead uld : Trigger.new){ lead uleds = new lead( Id = uld.id, Territory_Lookup__c = null, Territory_Area__c = null, Territory_Region__c = null, Territory_Theater__c = null); leds.add(uleds); } update leds; } } }
Test Class
@isTest private class UnitTest1 { static testMethod void protectFields(){ test.startTest(); List<Lead> lstLead = new List<Lead>{ new Lead(Company = 'JohnMiller', LastName = 'Mike', Status = 'Open', state='Karnataka',country='India',postalcode='5',LeadSource='Community') }; insert lstLead; lstLead[0].LastName = 'Mike'; lstLead[0].Territory_Area__c = 'sudhir'; lstLead[0].Territory_Region__c = 'sudhir'; lstLead[0].Territory_Theater__c = 'sudhir'; update lstLead; //CreateNewLead.CreateLead objcreateLead = new CreateNewLead.CreateLead(); test.stopTest(); } }
Thanks
Sudhir
Hi Claper,
How to find these lines can you please tell me the step to get
Thanks
Sudhir
On the upper right corner, click Your Name --> Developer Console --> File --> Open, search for the class, click Open.
Then there is button that will show you the lines that are covered in blue and the ones are not in red.
Line 23 and 52 to 57 and Line 68 to 78 are red in color please suggest me how to fix and get 100% code coverage.
Thanks
Sudhir
I am doing a lookup to custom object Territory_Lookup__c passing parameter I tried to tweek bit as you suggested code coverage dropped to 63%
I tried the same but no change code coverage is same.
Thanks
Sudhir