We've an inbound web service which is inserting/updating 1000s of records at a time. We've trigger which fires on update, but we noticed, it is 'only' firing for first 200 records at a time and skipping rest.
For e.g 1000 records are sent by external service, then trigger gets executed only for first 200, rest 800 are getting skipped.
On further analysis we found, that our static variable to prevent 'multiple' trigger execution in same transaction is getting 'set', after update of first 200 records, and because of that, trigger doesn't get executed for remaining records.
This surprised us and we find something similar mentioned in this thread :
I'm still having trouble in understanding above thread. This mentions that static variable are not 'set' for BULK API. In our case, this is just SOAP API which is inserting/updating 1000s of records. so my first question :
Q1 How different is bulk API w.r.t to SOAP API when 1000 records are getting inserted as far as handling static variables are concerned? As far as I know, in both cases, records will be implicitly broken into batch of 200 records , so if static variable is 'set' from false to true after first 200 records, then in both case, execution of code dependent on that static variable, would stop for next 200 records execution and so-on. Is that correct ?
Q2 I decided not to make my code dependent on static variable. So I've removed them and able to put other conditions for now to prevent multiple execution of same trigger( for e.g only on change of value, it fires) But I'm not finding it is not 100% fool proof as other developers in future could write code that could get executed multiple times(giving rise to 100 SOQL error etc) in absence of static variable. Is there any thing else I could do in my trigger ?
Q3 I'm thinking to make change in my inbound web service class itself which accepts list of records (could be in 1000s) .I'm thinking to devide, say 1000 records into batches of 200 records and call 'future' method to process them but problem is we've to send response back to service calling our inbound webservice . Using future then won't be an option. What other options I've to make change in the webservice class ?
Thanks for any direction in this regard.