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
Jon JaxJon Jax 

Best Practice: External Emails

Hello,
   I am relatively new to SF and would like to hear some opinions from senior developers/administrators. I am trying to find the best and most strategic way to handle this logistical issue, I will try to explain it very clearly:

I have the following Objects:
  • Jobs
  • Technicians
1. On each Job record detail, several Technicians can be assigned and I want to be able to send each Technician a confirmation email outlining details (merge fields) about the Job. Each Technician will need a different email template that would contain information specific to that Technician.
2. Ideally, I'd like to press one button ("Send Email" )and send those different emails out to those different recipients.
3. I would also like functionality that automatically marks checkbox fields (as True) on the Job layout that shows that those Technicians had been sent the confirmation email. 
4. Sometimes Technicians are changed. So for the final kicker and much more advanced functionality, when a Technician is changed, the associated checkbox field would be unchecked and one could reclick the "Send Email" button and it would only send to the new Technician with an open checkbox next to their name, but not to all of the techs who had already recieved an email. 

I hope this is easy to understand what I am trying to get at. With all that said, what do you think the best approach to this is? Custom Buttons? Flows? Visualforce pages? Apex Implementation? All of the above? Something I haven't considered? I don't neccessarily need specifics, rather a nudge in the right direction. Thanks for your time, your help is greatly appreciated! 
Carlos Campillo GallegoCarlos Campillo Gallego
Hi Jon,

Well... you have an interesting scenario here! Let's see if I've understood correctly:
As per your data model, you should have a junction object between these two objects you mention (Job-Technician) as you have n Technicians assigned to a job and a Technician can have jobs (it should! hahah).

My proposal:
This junction object, (let's call it Assigned Technician for example) would include the Job, the Technician, the type of Technician, a hidden checkbox field, and (not sure if it is really necessary) Technician's email.

Next thing you need is to create the email template, but instead of using typical standard email templates, this time we'd use Visualforce email template [1] which will give us more flexibility (and more work, of course).

The next piece of our jigsaw is a process created with Process Builder (great stuff, honestly), with this process we will be able to update child records without code [2], which will let us update Assigned Technician's hidden checkbox from the Job record when we put Job Status as "In Progress" (for example, you can choose whatever condition you want).
The last piece would be another process or a workflow rule which will launch the VF email template when the hidden checkbox is True.

So, the idea is that we will have this Job record, and then we will create the Assigned Technician records with it's hidden checkbox. Once we have all the Technicians assigned, we will update the status of the Job record, which will update the Assigned Technician child records and finally this will trigger the email sending.
The reason of using VF email templates is that you can add some logic to the template, so, we will use this capability to make the template dynamic in order to send only the appropiate info to the technician depending on the Technician type field value.

Hope this helps you :)

Regards,

Carlos.

[1]
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_email_templates_intro.htm

[2]
https://help.salesforce.com/HTViewSolution?id=000213419&language=en_US
Jon JaxJon Jax
Hey Carlos,
    Thanks for the reply and your proposal. That sounds like a really effective solution to this issue. I have many questions but I will dig into your explanations of the process and try to figure it out before I ask. Thanks again. /JJax 
Jon JaxJon Jax
Carlos,
   I like the VF email templates but I can't seem to be able to set the recipient of the email to a merge field. I found a solution: http://salesforce.stackexchange.com/questions/24100/add-recipients-to-visualforce-email-template

But I am guessing I need to implement an apex trigger to make that work. Am I wrong?  Do you know of a workaround for this roadblock? Thanks