Thanks for a very good proverb David…
I have been coding and pondering on some concepts….
–>Can i totally avoid an apex trigger by using a batch class for “trigger like situations –means situations when something happens ,something has to be done” ?
In what ways is this possible?
Should i put a scheduled batch job that checks every 5 minutes & does the necessary things like updates,etc…
Or is the concept of “doing something using only a batch class without the trigger” not possible at all when your situation is “trigger-like”
–>When all can we combine triggers and batch classes & how & what points should be taken care of in your opinion?
Thanks always for your precious guidance through this blog
You can go for the batch route, but it has some serious disadvantages vs using a trigger instead.
For example, I don’t think you can get a batch to run every five minutes! The minimum interval is longer than that, although you may be able to do some really hacky things to bring it down.
Another disadvantage, you can only have five batches running at once. So if over time you have six batches running every five minutes, one of them won’t execute because of the limit!
Another – batch logic doesn’t happen in real-time, and sometimes you’ll need the logic the execute immediately. This dead period could be the cause for a lot of stress as things can get out of sync then!
The good news is anything you’d want to do in a batch you can most definitely do in your trigger. Is there any particular reason you’re looking at batches instead?
Thanks for giving prompt replies always whenever you could.
No, there is no particular reason for using batch classes.
The scenario is:
There is a master detail relationship between 2 objects-say-“Object 1” is the master/parent and “Object 2” is the detail/child. The summation of a field -say-“Amount” of records of Object 2, must come in the “Sum of amounts” field in the parent record of “Object 1”.
If i cannot use Roll-up summary because of some reason(i.e rollup summary limit or there is a cross object formula in “Amount”),
I thought of implementing a trigger- which will calculate the current sum of “Object1” record whenever the associated “Object2” records are inserted,updated or deleted.
Now there could be many records (IN MILLIONS) of “Object 2” that will be inserted/deleted/updated, then STILL WILL THE TRIGGER BE THE BEST SOLUTION?? OR SHOULD I USE BATCH CLASS FOR SUCH THINGS?? OR SHOULD I COMBINE BATCH WITH TRIGGER ?? WHAT IS YOUR OPINION?? IF THE TRIGGER IS THE BEST SOLUTION FOR THIS SCENARIO,THEN I WILL GO WITH IT.
Go with the trigger =)
Yes, going with the trigger
Thank you always for this precious blog =)
Your email address will not be published. Required fields are marked *
Notify me of follow-up comments by email.
Notify me of new posts by email.
Enter your email address
Notify me of new posts!