I have a situation that is to create around 3000 records in a trigger. In my system when I create a record with some information I need to create the reference records for all the students in the create trigger. What would be the best approach for this scenario?
If we are to use a batch job, is it possible to run a batch by calling from trigger with parameters?
Thanks in advance,
Please correct me if my understanding on this is not correct.
I understand that when you create record, you would want a trigger to create a reference/ related record?
If so, I guess you can use the " Run Triggers on Related Records" type trigger. For more information, please refer to below documentation:
Thank you Mani for you reply.
But my scenario is, say I have student, course and student-course objects in my system. Whenever I create a new course I have to create a student-course record for every student in the student object. I can simply do this by writing an after-create trigger for the course object. So this trigger will loop all the student records and will create student-course records for all the students.
This is working fine but my only worry is since I am expecting to handle around 3000 students in the system, What will happen when this trigger tries to create 3000 student-course records? Will there be timeout issue or performance issue or any other..?
Is there any better way to achieve this requirement something like running a batch job?
Thank you Theirry.
As the time taken to create all the records varies time to time I am using a batch job for the purpose. But my worry is for every record Im running a query to get some parameter values.
I think it would be good to have few things with batch job like,
a calling mechanism to invoke a batch job from the scripts
a way to keep common scripts without repeating the same for every record (like a header),
a condition checking to decide whether to run or cancel the process.
Thank you all again.