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
Alexis KasperaviciusAlexis Kasperavicius 

Trigger or formula?

I could  really use some perspective and advice. I have an application where fields on a custom object need to be populated by combining choices from various select lists on parent and grandparent objects.

 

My issue comes up when the parent/grandparent select lists are changed - what's the best way to handle it?

 

  1. Should I use (somewhat complex) formula fields on the children that point up to the parents and combine the choices based on rules? ; or,
  2. Should I build a trigger with these rules which updates a static text field on all of the children whenever a parent is changed?

The benefits of a formula are that I don't have to touch what could be thousands of children everytime a select list is changed, however I am starting to have to dance around formula compiled character limits.

 

The benefits of using a trigger is that it's more flexible, the code is in one place and the formula compiled character limits don't apply.

 

I guess I don't know if I'm going to take a performance hit of some kind by using the trigger option and updating thousands of records - potentially many times if I have a user who keeps changing his mind on some naming scheme thereby continuing to update all of the children. A formula is just a live reflection of the parent so no update is neccesary. If I properly bulkify the trigger is that all I need to worry about?

 

Am I missing anything else? Is there best practice when it comes to this?

 

Thanks much for any persepctive.

 

Alex

 

 

chris.noechris.noe

Alex,

When faced with configuration vs. code as my solution, I always try and go with configuration (a formula in your case).  This will be easier to maintain long term and there is less system overhead involved.  However, if you are bumping up on the limits of the compile size for formulas, I would recommend going with the trigger approach now vs. later when the requirements change and you can no longer fit your logic into the formula.

Shashikant SharmaShashikant Sharma

Hi Lexles,

 

You can see this http://forceschool.blogspot.in/2011/05/hi-all-triggers-are-very-essential-in.html

 

Here comparison is between trigger and workflow which is same as yur case as its between configuration vs code.

 

Let me know if any further question on it.

AnnuAnnu

Hi Alex,

If it would be better to go with configuration(since you can make changes any point of time in production as well but for triggers, need to deploy the changes), but if the formula you are writing is exceeding the limit then it would be better to go with Trigger. if there is a trigger already existing, you can add the logic for ur code in it.

Abhay AroraAbhay Arora

Alex:

 

You need to go for formula fields its the bext approach you can have. if the Parent or Grand Parent is not acessible in formula then you can got for a trigger..

 

2.) Go for a trigger if you need to compare the old and new values of parent and grandparent ids