You need to sign in to do that
Don't have an account?
Radhe Shyam.
bulk insert in trigger
Hi Team,
I am trying to create a list in Trigger and adding the values in this list by iterating for loop.
After adding value, i am trying to insert this list out side for.
Things are fine if we are testing.
But when we are scanning our code by CheckMarx, it is saying that 'Need to be bulkify using collection'.
Am i getting this error because there is limit of 10000 record to insert in trigger?
If yes, then how to proceed with this?
Please Help.
Radhe S
I am trying to create a list in Trigger and adding the values in this list by iterating for loop.
After adding value, i am trying to insert this list out side for.
Things are fine if we are testing.
But when we are scanning our code by CheckMarx, it is saying that 'Need to be bulkify using collection'.
Am i getting this error because there is limit of 10000 record to insert in trigger?
If yes, then how to proceed with this?
Please Help.
Radhe S
I guess when you are iterating the loop and adding values in the list, it is crossing 10000 limit. You cannot have more than 10000 values in the List to perform any DML operations in one transaction. You have few options here
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_batch_interface.htm. This will break your updates in 200 per transaction but you can schedule it to run after every specific minutes.
It's really hard to advise without knowing your whole situation.
All Answers
I think you are using helper/handler class in trigger and your handler/helper methods are not bulkified.
Example :
to
you need to bulkify your methods by changing argument of single object to list.
Thanks,
Thanks,
I guess when you are iterating the loop and adding values in the list, it is crossing 10000 limit. You cannot have more than 10000 values in the List to perform any DML operations in one transaction. You have few options here
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_batch_interface.htm. This will break your updates in 200 per transaction but you can schedule it to run after every specific minutes.
It's really hard to advise without knowing your whole situation.
Can you please post your code here so we can help you
This is the error i am getting from checkmarx. on Insert the list of records.
I see couple of issues with the code and it has a lot of room for improvements. some mentioned here
Anyhow I would suggest to go with batch if you are expecting to working on the bulk updates greater than 10000.
There is also another following trick to handle collection less than 49999 using SOQL. It is called SOQL loop to load lists of 200 items at a time but it work with SOQL only. See if you can use this in your situation.
I hope this help.
Was above suggestion helpful?
By the way, issue was not the for inside for which i was thinking. Issue was insert stmnt which i placed here in trigger. I passed this list for insertion in batch and inserted there. It works. chkmarx error eliminated.
Thank you man for your active co-operation.
Radhe S