What do I have?
- Two objects ObjectA and ObjectB without any trigger/process builder/flow.
- I create a trigger on ObjectA to create the same number of records on ObjectB
What is my test case?
- Insert 9500 records in ObjectA and test if 9500 records are getting created in ObjectB.
What went wrong?
When I ran the logic to create 9000 records in the anonymous window, I get an error 'Too many DML rows: 10001'. Of course!
I moved my logic into a queueable class to ensure the DML of object B is not adding to the existing DML rows count and starts getting CPU TIME LIMIT ERROR.
My analysis:
- Even if I disable the trigger and run it for 6000 rows, the time is taken (debug: cpuTime) is approximately 11 seconds.
- With the trigger on, it comes as 13 seconds.
I want to know what I could do to ensure that at least 10k records in objectA can be processed without having the CPU timeout limit touched?