Salesforce is the #1 CRM solution in the world. To execute business logic fast and efficiently salesforce implements some automation process like updating any detail, sending emails or other activities. These automation processes are called Workflow in salesforce.
Let us dive into the complete concept of Workflows.
What is workflow in Salesforce?
Workflows or Workflow rules can be visualized as a container of several instructions. These instructions wait for certain criteria to fulfill. Once the criteria match, the action defined in the workflow will execute. It helps to automate many internal processes and procedure which ultimately saves time and makes the application more reliable. Workflow is triggered or invoked whenever a record is created or if there is any change in the record which already exists in the database.
Use of workflow in Salesforce?
- So you just read above that workflow rules in salesforce helps to automate business logic. let’s say we are creating 1000 new account records and we want to update the account status field of that record as Active, we can easily do it with workflow rules.
- If you have some knowledge or trigger you could question, these all things can be done using trigger then why do we still use workflow? The answer is the fundamental approach of salesforce development is to use as lesser coding as you can. Workflows are quite easy to create and implement.
I have written a detailed blog on Triggers and workflow vs Triggers, You can check that here: Triggers in Salesforce|Developer Guide
- Workflow also minimized human errors, just imagine if somebody tells you to update a field of 5000 records in 2 minutes how many errors you could do :-p
- Workflow helps to build trust with the customer and know them better, Example, you can set up a workflow to send emails to customer 30 days before their contract is expiring.
- Workflow is time Savier for CRM, suppose you have a Lead who is ready to invest say $500k in your business, you can set up a workflow to send an email to you whenever lead Amount > $400k and you can reach out to your prospect in time. Time is money as they say.
Components of Workflow
There are 2 main components of Workflow in Salesforce:
Criteria decided when and on which record the workflow will be evaluated. Criteria are further divided into :
- Evaluation Criteria
- Rule Criteria
Evaluation Criteria decided when the workflow will invoke. It mainly invokes when records are created and or getting updated. Evaluation criteria helps to evaluate the rule when a record is :
- Created and every time it’s edited
- Created, and any time it’s edited to subsequently meet criteria
Evaluation criteria “created” is self-explanatory, it evaluates the rule criteria each time a record is created. If criteria are met, run the rule. Ignore all updates to existing records.
Created and every time it’s edited
Evaluate the rule criteria each time a record is created or updated.run the rule if all the criteria met. Rules repeatedly runs every time a record is edited until it meets the rule criteria.
Created, and any time it’s edited to subsequently meet criteria
Rule criteria will be evaluated each time a record is created or updated. For a new record, run the rule if all the criteria met.
For an updated record, run the rule only if the record is modified from not meeting the criteria to meeting the rule criteria.
How does Created and every time it’s edited differs from created, and any time it’s edited to subsequently meet criteria
Suppose we have created the following workflow:
- Object: Opportunity,
- Condition : If Amount > 20,000
- Action: Update Stage = Closed won.
Created and every time it’s edited
Case: Amount entered is 30,000 so workflow will be fired and Stage will be updated to Closed Won. Now, if the amount entered is 50,000 the workflow will fire again trying to update the stage to closed-won.
Created and any time it’s edited to subsequently meet criteria
Let’s consider the same workflow mentioned above.
Case: Amount entered is 30,000 so workflow will be fired and Stage will be updated to Closed Won. Now, if the amount entered is 70,000 the workflow will not run again because in the
previous run itself workflow met the criteria and we know this rule runs only if the value changes from not meeting the criteria to meeting the criteria.
Rule criteria determine the record on which workflow will be implemented. Suppose you create 500 records and the workflow evaluation criteria are set as “Created”. You can select a specific record out of these 500 records for your workflow to work. Rule criteria help to it done.
Rule criteria will run the rule for that particular record only if :
- Criteria are met
- Formula evaluates true
Criteria are met: You can set criteria using dropdown and lookup options given
Formula evaluates to true: you can enter a formula that will return a “True” or “False.” value. Salesforce triggers the rule only if the formula returns “True.”
Actions are the actual activity that will be performed when your workflow in salesforce will execute. You can choose to execute the actions immediately when the rule runs or can delay the execution of the workflow. So Salesforce has categorized actions into:
- Immediate Actions
- Time-based actions
- Immediate Actions
As the name suggests, workflow performs Immediate Actions as soon as the rule evaluates the record. Immediate actions present for workflow in salesforce are:
- New Tasks
- New Email Alert
- New Field Update
- New Outbound Message
You can also select existing actions you might have created earlier. Let us understand each of these actions in detail now.
- This action is quite similar to creating a task on any object in salesforce. You could assign the task to any user or record creator, or to a specific role.
- For tasks, you would need to set the status of it like Not Started, Completed.
- There is another option of “Notify assignee” to send a “heads up” email to the task assignee.
- You can also set the due date of the activity like SLA expiration date plus #No. Of days.
New Email Alert
- Email alerts are great for sending automated emails to the designated recipients.
- You can select email templates given by default by salesforce or create your own customized email templates to be sent.
- Apart from the default recipient list, you can also add up to 5 email addresses.
- You can also select what will be the “from address” of the mail sent to the user.
- There are so many uses of this task like you can send a welcome email to new users, notify the user if any record is assigned to them, etc.
New Field Update
- New Field update actions provide you the option to update the field value.
- Select the object. Next, select the field of that object you want to update
- Use Re-evaluate workflow rules if you need the workflow rules on this object to be re-evaluated after the field value gets updated. if the field update results in a change to the value of the field, Salesforce re-evaluates all workflow rules on the object.
- In the specify new field value, You can select how to update the field values. Some of them are:
- A blank value(null) will remove any existing value and make it blank.
- Choose use a formula to set the new value to calculate the value using an expression, merge fields or other values.
Here I have taken Account object and field: Employees for example.
Here you will also need to understand Recursive Workflow and ways to avoid it.
Recursive workflow is the condition created if a field update for Rule1 triggers Rule2 and a field update for Rule2 triggers Rule1. Recursion would cause your organization to exceed its limit for workflow time triggers per hour.
We can avoid recursive workflow by either:
- Selecting the evaluation criteria as created, and any time it’s edited to subsequently meet criteria
- Not enabling “Re-evaluate Workflow Rules after Field Change”
New Outbound Message
- An outbound message sends information to external systems such as Java,.net.You configure outbound messages from Setup. And also configure the external endpoint and create a listener for the messages using the SOAP API.
- For Instance, whenever a record gets created in Salesforce, you want the same record to get created in the SQL server.
- You will need to enter the endpoint URL where the message will be sent and the list of fields which will be sent to the external service.
2. Time-dependent actions
Time-dependent actions execute at a specific time, such as 15 days before/after a record’s close date. When that specific time passes, workflow rule re-evaluates the record to confirm that it still meets the rule criteria. If the record still meets the criteria, the workflow rule executes those actions otherwise it will not.
You will need to add a time trigger as shown below:
And you can use the same immediate actions.
I hope now you have understood what a workflow in salesforce is and how it works. The below example is for you to analyze, take it as an assignment that you can do in your org.
Monitor Pending Workflow Actions
You can monitor the pending Time-Based workflow in Setup→ Quick Find→ Time-Based Workflow
To cancel pending actions:
- Check the box for the record you want to cancel
- Click Delete.
Best practices: workflow in Salesforce
- 1. Be careful with field updates – When using field updates action, be careful not to overwrite previous data.
- 2. Field updates only work from the Parent to Child – A field update cannot populate a field on an account from contact but it can populate a field on all contacts from an account.
- 3. Workflow emails will not log an activity – To log activity from a workflow email, you will need to create a second action to create a task as closed when the workflow is triggered.
- 4. You cannot deactivate a user if they are part of any workflow – admin must remove the user from all workflow actions before attempting to deactivate them
- 5. Make your email alerts useful – Think out your email alerts well before implementing them. Do not bombard users mailbox.
Limitations of Workflows
Each workflow can have a maximum of :
- 10-time triggers
- 40 immediate actions
- 40 time-dependent actions per time trigger
Workflow actions in a workflow rule, there can be no more than:
- 10 email alerts
- 10 tasks
- 10 field updates
- 10 outbound messages
For workflow hands-on go through Workflow Trailhead Modules.
For Important interview questions related to workflow definitely check Workflow Interview Questions-2020
To take up Automation to next level Do check Process Builders in Salesforce