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
Ken_KoellnerKen_Koellner 

Using Trigger vs. using Workflow

We've found there's a lot of things that can be done either with workflows or triggers.  These typically involve doing various updates to fields.  I'm curious if anyone has any patterns for when to use a trigger vs. when to use a workflow.  Ideas?

 

Best Answer chosen by Admin (Salesforce Developers) 
snugglessnuggles

hey ken,

 

as a best practice, always use workflows when possible.  i suggest this because workflows are native, they are optimized, they are easier to mantain, and you are less likely to run into programming errors that you could see with apex.  there are, however, some things that a workflow simple can't do.  a simple cross object field update or roll up summary information through a lookup relationship or getting the object owner's role to appear on a record, for example, would require a trigger. one other consideration is order of execution, which is explained in detail in the apex doc.  triggers will fire before workflow, so if order is a concern, a trigger can provide you with that flexibility.  all considered, i would do what ever is easiest.  use workflows when possible, and use triggers as a backup.

All Answers

snugglessnuggles

hey ken,

 

as a best practice, always use workflows when possible.  i suggest this because workflows are native, they are optimized, they are easier to mantain, and you are less likely to run into programming errors that you could see with apex.  there are, however, some things that a workflow simple can't do.  a simple cross object field update or roll up summary information through a lookup relationship or getting the object owner's role to appear on a record, for example, would require a trigger. one other consideration is order of execution, which is explained in detail in the apex doc.  triggers will fire before workflow, so if order is a concern, a trigger can provide you with that flexibility.  all considered, i would do what ever is easiest.  use workflows when possible, and use triggers as a backup.

This was selected as the best answer
twootwoo

Can I say that Account & Owner are cross object references?

 

If I want to retrieve the "Owner Role" of the Account object, it is not possible in a workflow?

It seems like from a workflow, I can only get the CURRENT User Role...

 

 

I am trying to update a field (which will be loaded by data loader) by a workflow.

The workflow will invoke an "field update" and set a flag to Y or N.

 

 

For example, if the data loader loads this record:

Account id = 1

SomeFlag = N

 

the workflow needs to pick this up and set the flag = Y if the Account Owner Role = "toggle"...

 

 

 

 

If my interpretation is correct, this is only doable in a trigger?

But how do I retrieve the Account Owner Role from SOQL?

 

 

 

Thanks in advance.