I have previously mentioned that one of the best practice principles I try to follow when developing within Salesforce.com, and the Force.com platform, is to leverage native builder functionality first. If my requirement can not be achieved through configuration (which is getting less every release), only then do I look at using Apex or Visualforce. One area where I am finding, more and more, that I no longer need to write code, and in particular Triggers, is for field updates.

Take an example where, say an opportunity stage is set to "closed won", I want to set the value of my field Next Steps to "Ring the Bell" to remind the sales reps to ring the big brass bell used to signal a sale (don't laugh – many companies have a bell, or bullhorn, or something!).  I could handle this in an Apex trigger set up to fire on Opportunity update: but workflow rules, and field update handle the process perfectly with no coding required. (always a good thing!)

Lets start by creating our Workflow rule as depicted below, to be executed when Opportunity Stage matches our criteria of "Closed Won"

Hit Save, and then add a new Workflow Action. We are going to choose Field Update, but you can see there are a number of additional options including Outbound Messaging which is a great way of handling web service calls, which can not be executed within the context of a Trigger (and you don't want to write an async method -see Nick Simha's great blog post for more details if you are interested). But for this example, Field Update is what we want.

Now create a Field Update Action like the following:

Fieldupdate

Save your changes and you are done. We now have a rule that executes upon Opportunity update, and sets the Next Step field to our cheesy status message. Keep in mind there are some limitations with this approach, most notably, you can only update a field on the same object as the workflow rule is executed upon, but good news is on the horizon. Thanks to the Salesforce Ideas site, cross object workflow is currently under consideration for inclusion into the product. I voted already, and I encourage you to do the same if this functionality is something you see as beneficial.

Get the latest Salesforce Developer blog posts and podcast episodes via Slack or RSS.

Add to Slack Subscribe to RSS