You need to sign in to do that
Don't have an account?
Code Not Covered by Class
Hello!
I am trying to update a Campaign Member from a lead when a lead interaction occures. The code works, but the code is not covered by the class for some odd reason. Can anyone let me know what may be the issue? I am only seeing 55 percent coverage with the items after the if statements not being covered: IE Lines 16-17 and 23-25
Test Class
I am trying to update a Campaign Member from a lead when a lead interaction occures. The code works, but the code is not covered by the class for some odd reason. Can anyone let me know what may be the issue? I am only seeing 55 percent coverage with the items after the if statements not being covered: IE Lines 16-17 and 23-25
trigger UpdateLeadForTrial on CampaignMember (after insert,after update) { for (CampaignMember cm: Trigger.New){ //Collect associated lead List<Lead> led =[select Id, In_trial__c from Lead where Id =:cm.LeadId]; For( Lead l: Led){ //Logic for when to fire if (l.In_Trial__c ==False && CM.Status=='Package Sent'){ //Updating value for In Trial field on Lead l.In_Trial__c=True; Update led; } //Running criteria for lead that is expired uncheck the In Trial field if (l.In_Trial__c ==True && CM.Status=='Trial Complete'){ l.In_Trial__c=False; Update led; }} }}
Test Class
@isTest(seeAllData=true) private class testClass_UpdateLastModifiedDate { public static testmethod void method1() { Lead l= new Lead(RecordTypeid=[select id,name,SobjectType from RecordType where Name ='SMB' and SobjectType='Lead'].id, Company='Test',LastName='test', leadsource='web',In_Trial__c=false,email='test@test.com',Install_Phone__c='999-999-9999',Status='0-Lead',OwnerId=[select id,LastName from User where Lastname='Sync' limit 1].id); insert l; task t2 =new Task(OwnerId=l.OwnerId,WhoId=l.Id,Subject='Call',Description='test',Status='In Progress'); insert t2; Account Ac = new Account(MegaPath_Department__c='Channel',OwnerId=[select id,LastName from User where LastName='Sync' limit 1].id, Name='testAccountName11',Type='Customer'); insert Ac; Contact c= new Contact(AccountId=ac.id, LastName='Chiles',LeadSource='Chat'); Insert c; Opportunity Opp =New Opportunity(OwnerId=Ac.OwnerId,Name='test',AccountId=Ac.Id,StageName='Prospecting',CloseDate=system.today(),ContactForRole__c=c.Id,Number_of_Sites__c='5', LeadSource='360 Communications - T1',NextStep='test',Install_Street__c='test',Install_State__c='CA',Install_City__c='test',Install_Zip__c='94582', Install_Phone__c='3157775695'); Insert Opp; Task t3 = new Task( OwnerId=opp.OwnerId,WhoId=c.Id,Description='test', WhatId=opp.ID, Subject='Call',Status='In Progress'); insert t3; Task t1 = new Task( OwnerId=ac.OwnerId,WhoId=c.Id,Description='test', WhatId=Ac.ID, Subject='Call',Status='In Progress'); insert t1; //Task t2 = [Select Status,ID from Task where ID =:t1.ID]; // insert t2; t1.Status='Completed'; Update t1; Campaign cp=new Campaign(Name='MP1 Free Trial',IsActive=TRUE,Free_Trial_Campaign__c=TRUE); Insert cp; CampaignMember cm= New CampaignMember(CampaignId=Cp.Id,LeadId=l.Id,Status='Request'); Insert cm; { CM.Status='Package Sent'; Update CM; //l.In_Trial__c=True; //Update L; CM.Status='Trial Complete'; Update CM; } l.Status='X - Lost/Nurture'; l.Lead_Disposition__c='Lost To Competitor'; update l; } }
Hi Kevin,
Please Try below code of Test Class & you get 100% code coverage.......
Thanks & Cheers,
Sagar Lakhani.