You need to sign in to do that
Don't have an account?

Batch apex vs triggers
I need to create monthly report of my data for my each and every user. So there could be lots of records if there are lots of user. These records are normally created by a batch process running weekly as an example that runs for hours to calculate all the monthly utilization records for each user.
.
I do not want to compromise with performance of my application especially on peak hours.
So should I continue with the batch process or do the same in real time using triggers? Or is there any other better way to achieve the same?
.
I do not want to compromise with performance of my application especially on peak hours.
So should I continue with the batch process or do the same in real time using triggers? Or is there any other better way to achieve the same?
Trigger:-
1) Processes synchronously
2) You can do 100 SOQL per cycle
3) Triggers process 200 in one context
Batch job:-
1) Processes Asynchronously
2) 200 SOQL per cycle
3) Depend on batch job size.
The trigger will invoke when you will do any DML on a particular Object. However, with batch apex, you can execute when you want or you can schedule with a scheduled job
Keep in mind though. Batch Apex runs asynchronously, which can make it hard to troubleshoot without some coded debugging, logging, and persistent stateful reporting. It also means that it's queued to run, which may cause delays in starting.
Also, there's a limit of 5 batches in play at any time, which makes it tricky to start batches from triggers unless you are checking limits.
https://trailhead.salesforce.com/en/content/learn/modules/asynchronous_apex/async_apex_batch
if you find this information helpful, please mark this answer as Best. It may help others in the community. Thank You
Anudeep