+ Start a Discussion
Somnath Paul 3Somnath Paul 3 

Behavior of Apex trigger in case of mass loading through Apex Data Loader

Hi All,

Just wanted to understand one concept of trigger. Suppose we are loading 1000 Account records in the batch of 200. Thers is a trigger written on the Accoount object on after insert event. Then how many times the trigger will fire and how should it behave.

Moreover, there in the handler class of the trigger webservice callout is written. Will there be any constraint on the governor limit of the call out in that case.

Thanks !!!

Regards
Somnath
srlawr uksrlawr uk
Hello,

If you load 1000 accounts into Salesforce, it will fire your trigger at least 5 times. Typically data is pushed through triggers in batches of 200. You can make the whole 1000 record load in a single action, and Salesforce will cut it into 200's for you behind the scenes.

Each of those trigger executions will then be governed by the limits.. https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_gov_limits.htm

And the limit is counted from entering the trigger to ALL syncronious (i.e. not @future) method calls until the end of the trigger.

In short, right there if you have a trigger handler that makes one webservice call out for each account that goes through the trigger, you're going to have a bad time. You can only make 100 web service call outs (see link above) in a single transaction.

If this is true, you will either need to find a way to batch your web service callouts (ie. change your service endpoint) or use a @future handler to Async process the records, in batches, after the trigger.