How to dispatch records from trigger to be processed by different threads in order to accelerate trigger execution and not to fail the whole trigger if the error happens.
if we update another records from trigger then they are locked. is there the idea of dispatching logic to process records in multiple threads so records will be locked seperatly?
What isues with locking should be considered with the following trigger code:
Database.update(highPriorityRecords, false); Database.update(mediumPriorityRecords, false); Database.update(lowPriorityRecords, false);
As I understand Database.update doesn't throw errors. How this can affects trigger execution time and record locking if there are large volumes of data(if we don't update all records at once but with seperate call - can we avoid full lock at once or it doesn't make sence, except that we use extra DMLs)
Triggers Although the flexibility of triggers is a great asset, triggers can cause many kinds of problems in your loads and integrations. Locks are one of those problems. When you’re loading records that fire one or more triggers, and any of those triggers performs either a select for update or a DML operation on records other than the record that you’re inserting, updating, or deleting, Salesforce locks those other records. These locks can in turn cause lock exceptions. Consider disabling trigger logic for your loads and integrations, or having a special, optimized code path for such activities.