I have a simple trigger that I'm trying to deploy, but am getting a 0% code coverage error when validating. I had to modify the test slightly to get around another problem (changed "static testMethod void" to "public static void") -- and I'm not sure if that's why the coverage isn't functioning properly or not. Here's my code:
Trigger:
trigger updateContactAfterConverted on Lead (after update) {
for(Lead lead:System.Trigger.new) {
// was the lead converted?
if (Lead.IsConverted) {
// query new contact
Contact newContact = [SELECT Id FROM Contact WHERE Contact.Id = :lead.ConvertedContactId];
// run @future class to update contact after conversion completed
updateContactAfterConvertedFuture.myMethod(newContact.id);
}
}
}
Class called in trigger:
public class updateContactAfterConvertedFuture {
@future
public static void myMethod(String newContact) {
// Find new contact
Contact updateContact = [SELECT Id FROM Contact WHERE Contact.Id = :newContact LIMIT 1];
// Set field to true
updateContact.Conversion_Completed__c = TRUE;
// Update contact
update updateContact;
}
}
Test:
@isTest
public class testUpdateContactAfterConvertedOrig {
public static void myUnitTest() {
// Create new test lead
Lead myLead = new Lead(LastName = 'Fry', Company='Fry And Sons', LeadSource = 'Advertising', Lead_Source_Detail__c = 'PPC');
insert myLead;
// Convert test lead
Database.LeadConvert lc = new Database.LeadConvert();
lc.setLeadId(myLead.id);
// Check conversion
LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
lc.setConvertedStatus(convertStatus.MasterLabel);
// Declare successful
Test.startTest();
Database.LeadConvertResult lcr = Database.convertLead(lc);
Test.stopTest();
System.assert(lcr.isSuccess());
}
}