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
sunilkbansalsunilkbansal 

Work Flow RUle - FIeld Update Vs Triggers

Hi,

 

I was wondering if we have triggers written on an object for insert/update events, is it advisable to have workflows with Field updates.

 

I was wondering checking rule criteria and then updating field based on that in Work flows, can be achived in triggers as well.

 

So why we use Workflows to update a field as updating field means again executing the triggers.

 

Please help me understanding Work flows and field updates.

 

Thanks,

Sunil

Best Answer chosen by Admin (Salesforce Developers) 
XhitmanXhitman

Thanks for clarifying your question sunilkbansal.

 

Yes I do recommend having the logic in the triggers itself since you are already into development. I personally try to put the logic in triggers rather than workflows since its quite a hassle for me to go through a lot of screens just to see the details of several field updates considering each field update could be done in one line of code.

 

Hope it helps!

All Answers

XhitmanXhitman

I think the question lies on the role and skills of the implementer:

 

Workflows are designed for Administrators since creating workflows doesn't have any coding experience needed. Creating triggers on the other hand are for developers since they will be handling Apex.

 

Triggers are more powerful and more flexible since almost anything that can be done via field update in workflows can also be done via triggers(correct me if I'm wrong.)

 

One difference between triggers and workflows is the maintainability. Workflows can be changed in production directly while changes in triggers need to be done in a sandbox or a Developer org before changes could be reflected in production. Triggers also need to have test coverage code so it generally takes more time to create triggers.

 

Let me know if its not clear enough.

sunilkbansalsunilkbansal

Hi Xhitman,

 

Thanks for the response. I agree with you all the points with you, but I have seen working with different clients, even if when we need to make any change in workflow then first we do it in sandbox, test it and then update the workflow in production.

 

Yes triggers require more maintenance.

 

Anyways I raised this question as I see that when we have existing triggers on one object say "Opportunity" and we have some work flows with field update on Opportunity. I saw that on update of Opportunity after the trigger workflows also update field on Opportunity,  which causes the trigger to fire again.

 

So my ultimate question is when WE HAVE existing triggers (which we cannot avoid)  on an object should not we try to get rid of workflows, I mean move the workflow logic to triggers.This way we avoid maintaining 2 different components also.

 

Thanks,

 

 

rungerrunger

I would recommend it, yes, just for ease of development and maintenance.  Keeping track of what's going on in 2 different places can lead to confusion.

XhitmanXhitman

Thanks for clarifying your question sunilkbansal.

 

Yes I do recommend having the logic in the triggers itself since you are already into development. I personally try to put the logic in triggers rather than workflows since its quite a hassle for me to go through a lot of screens just to see the details of several field updates considering each field update could be done in one line of code.

 

Hope it helps!

This was selected as the best answer
sunilkbansalsunilkbansal

Thanks Xhitman and Runger for confirming..

SFDummySFDummy

I have contract _type (formula field) and payment details depend on contract_Type

I have more then 30 fields to update. Payment details is a picklist.

 

I do not know how to write one workflow rule, so creating multiple workflow rules with field update and I will end up with 35 field updates (workflow rules)

 

Is it better to write trigger or workflow rule with field update in this scenario?

 

 

Sample data

contract_type        Payment (Picklist)

Simple Choice - CR026

Shared  CR100

Enhanced  CR064

Charter  CR356

Charter(10)         CR 356 80/50

Charter(25) CR 356 80/80/50

 

..........................   so on up to 35

 

appreciate any suggestions.

 

Thanks

Uma