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
Sam KamenskySam Kamensky 

Is it best practice to have your central logic lie in the code or on a record field?

I have three pieces of code on the Opportunity that do three different things.
However, one thing they have in common is that they all update a single field to some value.

I have two options. Either I can:
1. Have each of the three pieces of code update the field whenever their logic is found to be true
2. I can have a formula field on the Opportunity determine what the value should be, taking into account all three pieces of code, and use a workflow to update the value of the field to the formula value.

The advantage to number 1 is that whenever I or someone else looks at the code in the future, all of the components will be in one piece of code. 
I won't have to hunt around to find that field on the opportunity. I'll be able to see all of the functionality for each piece of code in one place.

The advantage to number 2 is that I can use the logic in workflows and I only have to update it in one place if there are any changes to how I want this field to get updated.
Personally i would opt for the second option.  This means that you have less code to maintain.  However if you want some added safety, you could do your workflows / formulas and then added Apex testing to verify that the workflow / formula is working as expected.