function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Glenn at MvistaGlenn at Mvista 

Testing Class for trigger on Converted Lead

Hi Community,


I have a trigger that takes the Contact ID that is created when a lead is converted and moves it back to a customer support Case. Works great using the lead.ConvertedContactId and lead.isConverted = true fields.


However, I cannot write a test class for this trigger because I cannot convert a lead via Apex nor can I insert a Contact Id into the ConvertedContactId field manually.


Any ideas on how to test this trigger?

Best Answer chosen by Admin (Salesforce Developers) 
Glenn at MvistaGlenn at Mvista

I found it - was looking in the wrong places.  For the record, here it is:



Database.LeadConvert lc = new database.LeadConvert();

Database.LeadConvertResult lcr = Database.convertLead(lc);


testLead1 and testUser1 are just records I inserted for the test.