Salesforce Certified Platform App Builder – 5 – Business Logic and Process Automation Part 5
- Introducing Workflow Rules
Introducing workflow rules. And so I’m in Setup and I did a search for the term workflow rules. And so the first page that comes up is a page that tells you how to understand workflow rules in salesforce. And so the main things that I want to cover in this particular lecture is just a high level overview of what workflow rules are. And so if you keep in mind that it automates is the following types of actions based on your organization’s processes. And so one of the questions on your platform at Builder Exam may have to do with the types of actions that can be performed via a workflow rule. And those would be to create tasks, email alerts, field updates, and outbound messages. And then on this page it’s helpful as you’re just beginning out on Salesforce. In order to understand workflow rules is to get familiar with some of these examples of things that you can do.
And there’s an example each for an example task that could be done, an example email alert, an example field update, and that’d be like changing the owner of a field. And then as well, an example outbound message would be this one here. And so the main thing to keep in mind is that there’s four types of actions you can perform or associate with a workflow rule and those would be tasks, email alerts, field updates, and outbound messages. Then as well, each workflow rule consists of a criteria that causes the workflow to run, there’s also immediate actions that can be performed, and then there’s also time dependent actions that can be performed. So the next few lectures we’re going to be walking through sample workflow rules and how to create immediate workflow actions and then as well, how to do time based workflow actions. So let’s continue on now into the next lecture where we cover creating workflow rules.
- Creating Workflow Rules
So let’s create a workflow rule. And so if we click the new rule button, we first need to select the object that we want this rule to apply to. And so we’re going to work with account records for this sample workflow rule and click Next. And then for the rule name we’ll call this rating Cold. And the idea here is we’re going to leverage that standard rating field on the account. Whereas either Cold, cold, warm or hot. We want to send an email alert in this example so that anytime an account is designated as Cold, it sends an email alert out to alert us that we need to take some sort of action.
And then for the evaluation criteria, you can set this to fire for the workflow rule, either when an account is first created or you could specify whenever it’s created and every time it’s edited. One thing to keep in mind is that you cannot add time dependent workflow actions with this option. So we will be doing either time dependent workflow actions or immediate workflow actions in later lectures. And so for now, we’re going to select created and anytime it’s edited to subsequently meet the criteria. Which means that this rule is evaluated when a record is created and when a record that doesn’t meet criteria is edited to meet the criteria. So this criteria that we’re going to meet is we want to find the rating field, which is that standard field that we looked at previously.
And this is a picklist field. So this search window comes up or this lookup window, we can pull up the different values of that pick list field and we want to specify the criteria as when it equals cold. So we’re going to insert selected and select the operator of equals so that when the account rating equals Cold, we want to perform an action with this workflow rule. So we click save. And next and so now here’s where we specify the workflow actions and we can either do immediate workflow actions or time dependent workflow actions. And so in the next lecture we’ll get into creating immediate workflow actions.
- Immediate Workflow Actions
So to create an immediate workflow action, you’ve got to first have a workflow and then you add the workflow action by clicking the down button here. And so we’ve discussed previously the different types of actions you can perform from a workflow and that would be a new task, a new email alert, a new field update, a new outbound message, and then you could as well select an existing action. If you’ve previously created workflow actions, you could select them here. But we’ve not done that yet. So we want to create a new email alert in this example. Another thing to note is that you’re not able to create new records and so workflow rules cannot create new records. If you want to create new records, you’ve got to either do a trigger or do something like the process builder which we’ll get into later. But for now we’re just creating an email alert.
We need to give a description and name this email alert. Then you select an email template. Now you may want to create an email template prior to this. I’m just going to use one of the example ones that are available to us. You can look in different folders for email alerts or save email templates to different folders and we just have the unfiled public email templates available to us. And so I’m just going to select one of these. It doesn’t really matter for sake of the example. I’m just going to say this is an escalated case notification. Now we’re not dealing with a case, we’re dealing with an account. So it’s not the best example, but you could go in and create an email template. So it will suffice to just select an email template just for sake of the example. And then we can select a recipient type for this email alert. It could be the account owner, it could be an account team, it could be an email field on the account if there were one, there’s not any.
So this is blank. You could do the related contact record or related user for example. And so in our example here, we want to send an email alert to the person that last modified the account record. And so that stands to reason that if someone has been going in and modifying the account, they’re showing the most recent interest in the account. So we’re going to send them an email alerts and that this account has been set to Cold. Now if they’re the most recent to modify it. And this is triggering when the account has been created or edited. And that stands to reason that they’re the ones that actually did specify the account as cold. And so what we could do in this scenario is send them an email reminder that they need to take some sort of action since the account has been rated cold by them. You could also specify additional email addresses.
These don’t have to belong to salesforce users. So you could send these to personal email addresses or other internal employees that don’t have a salesforce account. You can have this be from the email address of the current user. So we’re going to click save in order to complete the immediate action for this workflow rule. And so other actions you could do is you could perform filled updates or create a task. A task would be like a reminder to do some sort of action as well. And then as well you could do to an outbound message and that’s where you can send things to other systems and that those could then be consumed through an API.
- Time Based Workflow Actions
So now we’re picking up with creating a time dependent workflow action. And so previously we created the immediate workflow action of the email alert. And this is whenever an account is rated as cold, it’s sending out the email alert to the person that last modified the account. And this is an immediate reminder via email. We could add a time trigger for a time dependent workflow action. Instead we’ve got to create the time trigger first to specify when this needs to fire. And so the workflow that this is associated with is displayed here. And we can specify a numeric value in either days or hours and then before or after these different sorts of criteria. Either the rule trigger date of when this workflow rule fired, or the account created date, the account last modified date, or the account SLA expiration date. This is really these fields that display are dependent on what object you’re working with and what sort of date fields you’re dealing with.
And so I want to do this for example, one day after the rule fire, so we have the email alert that sends immediately. And then what I want to do is do a follow up reminder one day after the rule trigger date and I want to click save. So now I have my workflow time trigger created and so now I can create my time dependent workflow action. You notice here that I have the time trigger and this is kind of confusing. You’ve got to create the time trigger and then you add the workflow action. It’s important to understand this, and this may be on the exam as well, is in addition to the immediate workflow actions, you can do the time dependent workflow actions, but first you have to create the time trigger. Okay, so we’ve got the one day after the rule trigger date and then we add the workflow action.
Once again, it’s the same type of actions that we could create previously with the immediate workflow action. So the thing to bear in mind is that there’s four primary things you can do. It’s a new task, a new email alert, a new field update, or a new outbound message. And then in addition to that, you can select an existing action which would be one of these four types. And so previously we did an email alert for this time dependent rule. I want to add a new task to the equation. And so to creating a new task, I can assign this to myself. I’m going to perform a search by clicking the icon there to pull up my search result. Select that and then you enter in a subject for this task.
And this is like a calendar reminder and outlook, if you’re familiar with that, this will give you a pop up and it’s a reminder to perform a task in salesforce and then you can mark it as complete when you’re done. And then you can give a due date as well for that task. So we’ll say that the due date will be the rule trigger date. Plus one day this will be in sync with our trigger for our time based workflow action. And so it will give the due date the same day that the task appears for me. So we want to do a status of the default of not started a priority.
I’m going to say that this is a high priority because the account has been rated as cold and in the comments you can add comments to direct the user for further details for their task. I could create additional tasks here by clicking Save a new but I’m just going to click Save to go back to the screen and show now that we have a time dependent workflow action. And so you notice we have our immediate workflow action of the email alert. And then one day after the rule trigger date, we have a task being created and assigned to myself. So I’m going to click Done to round out the experience of creating this workflow rule that has two associated actions with it. That would be one that is immediate and one that is time dependent that we’ve done through the previous couple of lectures. And so now finally, to finish out this workflow rule, we want to be sure and activate it so that it fires for us in our instance. So if I click activate and click OK, then we’ve activated our workflow rule. Now, since this is a new instance of salesforce, we need to specify a default workflow user.
And so it’s recommended that you choose someone with system administrator privileges. So choose yourself here. I’m going to choose myself by doing a search and selecting for the link. And so I’m not going to check this checkbox. To enable email approval responses, I’m going to leave that unchecked that has to do with approving or rejecting approval processes via email and people could type in the word approve or reject in the first line and adding comments in the second line. To approve or reject salesforce approval processes, I’m going to leave the rest of these unchecked and click Save. And so that is a process automation setting that basically has to be done in order to run workflow rules is you have to have a default workflow running user. So now that we’ve activated our workflow rule, we want to next go into helpful practice activity where we create a time based workflow.
- Introducing the Time Based Workflow Queue
So now that we’ve created time based workflow actions, it’s time to introduce the timebased workflow queue. And we left off creating a time trigger on this workflow for the Rating Cold workflow rule. And that’s whenever an account rating equals Cold, we perform these actions. The immediate workflow action was an email alert that goes out. The time dependent workflow action was a task being assigned to a user. Now it’s hard to figure out or test things that are set to go in the future. So that’s why Salesforce has provided the time based workflow queue. And so you can find that by searching for the word time in Setup and that will bring up the time based workflow. So clicking on that from Setup brings up the time based workflow screen and you can filter results by specifying different criteria above, such as workflow Rule, name object, scheduled date, et cetera. Or if you want to see everything that’s in your time based workflow currently, just simply click on the search button. Right now we have nothing in our time based workflow queue.
And so what I want to do or demonstrate is how to get things to start to flow into this time based workflow queue. So I’m going to go back to the Avid Insurance record and I’m going to adjust the rating field to Cold in order to trigger this workflow rule. So I’m on the details tab for Avid Insurance and I’m going to go to the rating field. This is the standard rating field with the Hot, Warm and Cold designations and we’re going to set Abbott Insurance to Cold and click Save. And so now we see our validation rule Fire as well that is active. It’s saying that an account number must be seven characters long. So you notice that that validation rule is keeping me from being able to do an update on the record because now we have an active validation rule on the account object as well. So I’m going to enter an account number of seven characters long on Avid Insurance and click Save to dismiss the validation rule error.
And now we’re going to go back to set up and go back to the time based workflow queue by once again searching for the word time and set up, clicking on it in the menu on the left and then clicking Search without adding any filters. And now we see that there’s one rule that’s scheduled to fire and that is one day from today. So it would trigger it on today, which happens to be December 8 of 2016. This is a scheduled job that’s scheduled for one day and the corresponding workflow rule is this rating Cold Workflow. And so another thing I want to explain about the time based workflow queue is that once something flows into the queue here, it will remain there until the record no longer meets the criteria. So if I were to not update Avid Insurance for the next day, then I would have this task assigned to me from this workflow rule tomorrow. Now if I were to go into the Avid Insurance record and adjust their rating to warm or hot, it will remove that from the time based workflow queue. And I wouldn’t get the task assigned because it would no longer evaluate the true when the time came for it to fire. So I’m going to adjust the rating on Avid Insurance to warm and then I’m going to click save. Now let’s return back to the time based workflow queue and we’ll click search again to see if it has removed this item from the queue. And so as you see now, it’s not scheduled to fire tomorrow. And so the timebased workflow queue is an effective way for you to test time based triggers with your workflow actions and see what is set to fire and on what date and what corresponding workflow rule and as well what object. So you can also filter this by these different criteria.
And so you may think, well that’s not really necessary to be able to filter to this level five levels deep of and statements. But there’s actually a limit of 1000 workflow actions that can be performed per hour by default in your organization. And I’ve dealt with larger organizations that have literally tens of thousands of time based workflow actions that occur each day. And what happens is it’ll process the first thousand and then it waits an hour before it processes the next thousand. You can contact salesforce by logging a case and ask for them to increase that limit. But if you’re pushing up against limits, usually you have to resort to code at that point. And so we ended up converting a lot of the time based workflow actions to apex code and triggers that were set to fire at certain times and batch jobs and scheduled jobs and avoided those limits instead.
And if you find yourself in a situation in a large salesforce organization with tens or hundreds of thousands of records that are needing to be updated at certain times and hitting these limits, you’ll experience it’s much like filling up a bathtub and draining a little bit of water, but having more water coming in than it’s draining out. And eventually it will overflow or hit its limits. And that’s the same sort of scenario here with the time based workflow queue and with some of these time based actions you can set things to fire well out into the future. And so over time this can really start to back up. You shouldn’t experience this behavior in your own free developer account here, especially through this course, but it is an important tool for you to be able to test time based events.
So just keep in mind that it’s the time based workflow and it goes hand in hand with any time triggers that you create on workflow rules. So we spent quite a bit of time on workflow rules and I want to revisit the one that we did previously and recap a few things before we move on to the next lecture. So if we go to the workflow rules list here and set up and then select our Rating Cold Workflow rule, you recall that a few of the actions that can be performed are an email alert and then a task and then as well. Another thing to specify is that you cannot add new time triggers to an active rule. You have to deactivate a rule to add additional time triggers.
If I were to edit these workflow actions and do additional immediate actions, you can do that. So the main thing to keep in mind is in addition to the creating new tasks and new email alerts, you can also do field updates and outbound messages. You may be asked on the exam what are the four types of actions that can be done either immediate or time based via workflow rules? And those are task, email alert, field update and outbound message. And so now that you’re aware of the different types of actions you can do through workflow rules and have been introduced to the timebased workflow queue, it’s time to now be introduced to the cloud flow designer.