I have a pretty big class which does a lot of things, so in total its taking ~10-20s for its main method to run. However, ~8s are taken up by Database.leadConvert(). Any ideas why? Could it at all be related to the code that's running before it? Here is how all leadConvert records are being created:



Example 1

enter image description here

Running Database.leadConvert with the same leadConvert settings for 3 leads in the Execute Anonymous Window yields better results, incomparable but still slow.

LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
Lead[] leadsInsert = new Lead[]{};
Lead myLead1 = new Lead(LastName = 'Fry', Company='Fry And Sons');
Lead myLead2 = new Lead(LastName = 'Fry', Company='Fry And Sons');
Lead myLead3 = new Lead(LastName = 'Fry', Company='Fry And Sons');
insert leadsInsert;

Database.LeadConvert[] leadConverts = new List<Database.LeadConvert>();
Database.LeadConvert lc1 = new database.LeadConvert();

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

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

Datetime now = Datetime.now();
system.debug(' ----------------------------- running convert');
Database.LeadConvertResult[] lcr = Database.convertLead(leadConverts, false);
system.debug(' ----------------------------- run took ' + (Datetime.now().getTime() - now.getTime()) + ' milliseconds.');
16:02:43.1 (118336976)|USER_DEBUG|[12]|DEBUG| ----------------------------- running convert
16:02:45.918 (2919409711)|USER_DEBUG|[14]|DEBUG| ----------------------------- run took 2801 milliseconds.
16:08:30.1 (120179985)|USER_DEBUG|[31]|DEBUG| ----------------------------- running convert
16:08:32.880 (2881381162)|USER_DEBUG|[33]|DEBUG| ----------------------------- run took 2761 milliseconds.

Edit: This is all in my sandbox environment, which is a partial copy.

  • WFRs, Process Builder, Flows on the converted objects? Duplicate rules running on the converted objects?
    – cropredy
    Commented Apr 2, 2020 at 14:28
  • One WFR on contact and that's it. Tons of WFRs on Opportunity but we're setting doNotCreateOpp to True. Please check my edit as I forgot to mention. Commented Apr 2, 2020 at 14:45
  • Managed Packages? Dupe Rules? I never saw a lead convert take 5 seconds, but maybe 3 is not that out of the question Commented Apr 2, 2020 at 17:09

1 Answer 1


This isn't unusual, especially if you have installed some managed packages or have heavy triggers. The time required, without an opportunity, would be the same as a full update operation on a Lead, an insert or update on an Account, an insert or update on a Contact, plus additional time to reparent child records (tasks, events, campaign members, etc). As a comparison, it does take close to 8 seconds in our production org to convert one lead (two or more in tandem would result in a CPU LimitException). By contrast, in a blank scratch org, it takes less than 400ms to call database.convertlead. It really depends on how much logic you have running in the background.

  • Yes. As you can also see in the screenshots, we have MC4SF as a managed package as well as EDA and according to your suggestion I think they are the culprits. Even though MC4SF shows up after leadConvert, There are very few triggers (logic, etc.) on Lead and the "converted to" objects so by elimination it has got to be those two packages. Commented Apr 3, 2020 at 6:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .