Process Builder + Flow + Email Templates = Awesomeness
Sometimes there are multiple ways to complete the same goal within Salesforce. Not every method is going to be very admin-friendly. For example, I want to send an email when the Opportunity is closed won out to everyone in my company. In that email, I want to give a list of the Opportunity Products. Opportunity Products is a related list so I cannot use straight up merge fields on an email template. I could create a visualforce email template but not every admin will find that very friendly.
So what are my options?
I gave this some thought and came up with a few ways I could achieve my goal. During this part of my process there are no bad ideas. My whole goal is to list as many options as possible and then go through the list and throw things based on their pros and cons. This way, if a chosen method doesn’t work out I already have a list of backup options.
- Visualforce Template
- Apex to send the message and define the body
- Put the product information in a field on the opportunity *somehow*
- Send separate emails for each opportunity product
- Convince people we don’t really need product information in this email
I wanted this to be as Admin friendly as possible. I don’t want to spam people so sending multiple emails was out of the question. That meant I need to think how can I get Product information in a field on the Opportunity.
The answer hit me. I could use Flow.
Flow It Up
My Flow would actually be pretty simple.
- Get the Opportunity ID
- Use a Fast Create to get all the Opportunity Products
- Loop through the Opportunity Products
- Build up my data
- Use a Record Update and set my new product data to an Opportunity Field
We can take this one step further. We can plan on using an HTML email template we can put HTML in our Opportunity field and create a nice looking table. That’s where the multiple Assignment elements come into play. I have a text variable called “vrOutput.” The variable default value is simply “”
If I wanted I could also put the headers here, but I decided to not have headers on my table. Each time I reference this variable in the loop I’m adding, or appending to that value.
The first assignment element is assigning a new row, “<tr><td>”
The next element is where I insert the Product information into the table. I technically don’t need two assignment elements, but it just feels cleaner to me.
For screen capture purposes, here’s what it looks like with just the Product Name and Product Total.
Now that we have our fields created, we can create our email template. I’ll need an HTML or Custom email template so the HTML in the field renders properly. But we still have 2 issues. How are we going to launch this Flow and how will we send our email template.
We could use a Workflow Rule to send the email template, we could even do it in a Flow (send an email alert). We could also add a custom button that people must use in order to change their Opportunity to Close Won.
We could do that and would make sense if I were doing other things with Flow when the Opportunity moves to Close Won (like custom validation across related objects). I wanted something more simple
Enter Process Builder. I can call both my Flow AND my email alert as actions in the Process Builder. I just need to make sure that my Flow is the FIRST action in the list followed by the email template. Actions fire in the order they are listed (based on my experience thus far). If I was really paranoid, I would have Process Fire the Flow and then re-evaluate the process to see if our Field on the Opportunity got filled in and use that as the cue to fire the email template.
We have a lot more power now with Flow and Process Builder. I no longer need to create a visualforce template. What’s very cool is I’m not limited to the number of related objects I want to include! Want to include Products and the last 5 Tasks? No Problem! As long as you have a way to query it you can include the data.
What other ways can you see using this method of rolling up children information to the parent?