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
edralphedralph 

Is trigger execution single threaded?

Quick question: I have a before update trigger on the Lead object and would like to know what happens in this scenario:

1. Bulk data import of leads (let's say 1000) cause it to fire.  It'll fire 5 times if the batch size is 200.
2. During the processing of one of the batches of 200 above, a web service pushes a Lead into the system, firing the same trigger.

Will the trigger in 2 wait for one of the batches of 200 to finish before executing or will it run while the (same) trigger in 1 is halfway through processing a batch of leads?
 
Best Answer chosen by edralph
Ankit SinghAnkit Singh
Hi Edralph,

There are chances of both the batches running concurrntly as Up to 5 batch jobs can be queued or active concurrently. About the first question, since both the triggers are from seperate contexts definitely trigger 2 will be fired and it won't wait for 1 to finish.
 

All Answers

edralphedralph
** before insert
PrasathPrasath
Hi edralph,

If you Enabled the Bulk API option on the data loader then it will process records asynchronously.
edralphedralph
Thanks for the reply @prasanth, however, I'm not asking that question - I'm asking whether there is a possibility that two separate batches could execute at the same time (asynchronously to the original request or not).  If not, then I don't need mitigate for that in my code.
Raj VakatiRaj Vakati
I dnt see anywhere document this one .. but chance are there which leads for unable to lock the records  

two asynchronously batches may execute the same time on same data and you need to lock the records to avoid unable to lock the data 
Ankit SinghAnkit Singh
Hi Edralph,

There are chances of both the batches running concurrntly as Up to 5 batch jobs can be queued or active concurrently. About the first question, since both the triggers are from seperate contexts definitely trigger 2 will be fired and it won't wait for 1 to finish.
 
This was selected as the best answer