I am writing a test to test lead conversion. The test is failing because the lead has a failing lead validation rule that checks a custom field value that is set using a Before trigger. However, even though we have the
Enforce Validations and Triggers setting turned on, during the test, the Before trigger doesn't appear to be firing.
Here's the relevant bits of the test code:
// convert the lead with signed status Database.LeadConvert lc = new database.LeadConvert(); lc.setLeadId(l.id); LeadStatus convertStatus = [select Id, MasterLabel from LeadStatus where IsConverted = true limit 1]; lc.setConvertedStatus(convertStatus.MasterLabel); Database.LeadConvertResult lcr = Database.convertLead(lc); // assert the lead was converted System.assert(lcr.isSuccess());
In the trigger, I placed this line to see what's going on. During a normal run the output works. During the test, it doesn't fire at all.
System.debug('Lead Trigger: ' + Trigger.operationType);
There's only one trigger for Lead and the first line is the debug statement. The trigger just isn't getting fired for some reason.
Does anyone know if a Before triggers should fire whilst testing the lead conversion process?
Is there anything I need to set before executing the conversion process?