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
gslatergslater 

Bulk Lead Convert - Trigger called multiple times?

Test.startTest();
        
        System.debug('$$$About to convert: '+lc);
        
        Database.LeadConvertResult[] lcr = Database.convertLead(lc);        
        
        for(Integer i = 0; i<lcr.size()-1; i++){
            System.debug('###$$$' + lcr[i]);
            System.debug('Success? '+lcr[i].isSuccess());
        }
        
Test.stopTest();

 

lc is an Array of LeadConvert objects, and the convertLead operation is correctly processing 4 Leads. All are successful from the LeadConvertResult output, and all get the correct Account and Contact populated (I set Opportunity not to insert).

 

Problem is - the after update trigger I wrote on Lead is being called 4 separate times (i.e. Trigger.new size is 1 every time).  I don't know why this would be as from the docs you can do a bulk convert.  I don't understand why the trigger is not receiving all converted Leads at once.

 

Can anyone help?

 

Edit: when trigger is called 4 separate times, it is not the same record that is being processed but the 4 separate records.

 

TejTej

my first thought is are there any workflows on that object updating any fields?? if yes that might be the reason

gslatergslater

There are workflows - a lot of them.  But if the workflows updated the Lead and the trigger was called again, wouldn't it be the same record that enters the trigger?  Because in this case each Lead enters exactly once.

TejTej

we have the same issue couple of months ago, once we moved the workflow logic into trigger, it resolved, n trigger gets fired one time only.

 

if you dont want to move the work flow logic into trigger, u shud write a trigger helper class which prevents the trigger from running multiple times.

 

 

gslatergslater

We can't find any workflow that does anything with Leads.  I'm curious - can anyone confirm they have actually done bulk lead convert and a single trigger has been fired with multiple objects in the trigger.new?  Because it seems impossible to do with the dataloader, only Apex. 

 

I've tried everything and the trigger keeps firing once per record.