3

I'm having some trouble setting up a testing class for a trigger that i wrote to populate a custom object with fields of a lead on lead conversion, in addition to the standard (Account, Contact, Opportunity) objects.

My test code is essentially creating a new lead, assigning it some default values and converting it through the Database.ConvertLead() method. I keep trying to tweak it, but my code coverage for my lead after update trigger is still 0%. Any thoughts would be greatly appreciated.

@isTest
public class TestCreateApp {
    static testMethod void insertNewLead() {

        Lead newLead = new Lead();
        newLead.LastName = 'Lee';
        newLead.FirstName = 'James';
        newLead.Lead_Status__c = 'Open';

        insert newLead;

        Database.LeadConvert lc = new Database.LeadConvert();
        lc.setLeadId(newLead.id);

        test.startTest();

        LeadStatus convertStatus = [Select Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
        lc.setConvertedStatus(convertStatus.MasterLabel);

        Database.LeadConvertResult lcr = Database.convertLead(lc);
        System.assert(lcr.isSuccess());

        test.stopTest();
    }

}
  • 1
    Is the lead trigger active (stupid, I know but it has to be asked)? Can you clear your code coverage and try running the test again? Can you examine the debug log of the test, look for the trigger's name. – eyescream Dec 24 '13 at 21:43
  • Yes, the trigger is active and seems to be working correctly. After clearing the code coverage it seems to be working. Sorry I am a bit new to Apex development, so sorry if these aren't great questions, but thanks for helping me out again! – James Dec 24 '13 at 23:08
  • Don't worry, there's nothing wrong with you ;) SF guys are in progress of making changes to how coverage is calculated and stored, quirks like that are kind of "known bug" by now... blogs.developerforce.com/engineering/2013/11/… Can you answer the Q yourself (I'm rolling off to bed now) and mark it as accepted later on? We're trying to improve our stats of 90%+ answered questions ;) – eyescream Dec 24 '13 at 23:14
1

Fixed after clearing the code coverage.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.