function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SFDC_RJSFDC_RJ 

Trigger vs scheduled Batch Class

I have to update a field on opportunity I want to do as as user updates the record but also to make sure all records have right value all time was planning to also write a batch class that could be sheduled. It is like writing the same code once in Trigger and also in batch class. I am new to apex looking for advice what should be done in these scenarios.
Gururaj BGururaj B
You want  to update a field based on any other  field updated by user on the opportunity record? This can be done using the process builder. Create process builder on Opportunity on record update with critria mentioning our condition that should match before updating your field. If you dont have any condition and it has to update all the time, then you just create a formula with 1=1 and on the TRUE condition add a action to update a record on Opportunity where you can update your field.

If this process builder is well tested in all the scenrio i dont think you need the redundant batch job to do the  same task. I suggest you go for process builder and no need of any batch job if the inention for that batch job is also same as this process builder.
SFDC_RJSFDC_RJ
Thank You for your response but the logic to my calculations is complex I ran into formula limits so opted for trigger.
Gururaj BGururaj B
Then go for trigger. But i dont think you should having same functionlity on trigger and batch. Its redundant and simple consumes your resource and limits.
SFDC_RJSFDC_RJ
I agree it is redundant and that is what I am looking a solution for. I definitely want to do scheduled apex as I have experienced how sometimes triggers don't fire :( I am new to Apex would appreciate your advice. Thank You