You need to sign in to do that
Don't have an account?
AlSawtooth
Need help with test coverage for very simple trigger
Here is my trigger (thanks to help from Ashlekh (https://developer.salesforce.com/forums/ForumsProfile?communityId=09aF00000004HMG&userId=005F0000003FjAE&showHeader=false)!):
Here is my test class, but I'm only getting 43% coverage. What else can I add to the test class to cover the rest of the trigger?
Thanks!!
trigger UpdateEmployerAddress on Contact (before insert, before update) { Set<String> setoforgs = new Set<String>(); for (Contact inloop : Trigger.new){ if(inloop.Employer_Lookup__c !=null){ setoforgs.add(inloop.Employer_Lookup__c);} } Map<id,Organization__c> orgs = new Map<id,Organization__c>( [SELECT Id, Mailing_Street__c, Mailing_City__c, Mailing_State__c, Mailing_Zip_Code__c, Mailing_Country__c FROM Organization__c WHERE Id in :setoforgs]); for (Contact inloop : Trigger.new){ if(inloop.Employer_Lookup__c !=null){ if(orgs.size()>0 && orgs.containsKey(inloop.Employer_Lookup__c)){ Organization__c o = orgs.get(inloop.Employer_Lookup__c); inloop.cv__Employer_Street__c = o.Mailing_Street__c; inloop.cv__Employer_City__c = o.Mailing_City__c; inloop.cv__Employer_State__c = o.Mailing_State__c; inloop.cv__Employer_Postal_Code__c = o.Mailing_Zip_Code__c; inloop.cv__Employer_Country__c = o.Mailing_Country__c; } } } }
Here is my test class, but I'm only getting 43% coverage. What else can I add to the test class to cover the rest of the trigger?
@isTest private class UpdateEmployerAddressTest { static testMethod void EmpTestMethod() { Organization__c o1 = new Organization__c(); o1.Name ='Test Org'; o1.Mailing_Street__c = '123 Main Street'; o1.Mailing_City__c = 'Brooklyn'; insert (o1); Contact cons = new Contact(); cons.LastName = 'Tester'; cons.cv__Employer__c='Test Org'; insert(cons); Contact cons2 = new Contact(); cons2.LastName = 'Tester2'; cons2.cv__Employer__c = 'Nope'; insert(cons2); System.assertNotEquals(o1.Id, cons2.Employer_Lookup__c); System.assertNotEquals(o1.Mailing_City__c, cons2.cv__Employer_City__c); } }
Thanks!!
For instance add the following to between 13/14:
cons.Employeer_Lookup__c = o1.Id;
That should drastically increase your code coverage.
Do you see any other reason for such low coverage? And thank you!