Email Alert to Parent object's email field without apex

Workflow! When you hear this term, a fantastic way to automate many business processes comes to your mind. Using workflows in Salesforce, you can do many things and this needs only a few clicks.

You can perform various actions using worklow like updating a field, creating tasks, sending outbound messages and email alerts.


A few years back, we got a requirement in a project where an email notification needs to be sent to opportunity owner and owner's manager if the opportunity stage turns to "Closed Won". So the requirement was simple, we just created a workflow rule with the specified criteria and created a workflow action to send the email alert. wait, wait, wait!! It was looking simple but while adding recipients to the email alert, we got stuck. There is a limitation associated with workflow email alert, we can add email fields as recipients if those are on the object for which we are creating workflow. In our scenario we needed to send email alert to the owner's manger also and manger field was on the user sObject, after that we created a formula field on the opportunity object that was referencing the owner's manager email field. Then we tried to use that formula field in the email alert, but only email type fields can be set as recipient. Then we failed to implement the email notification using formula field also.

Then we ended up with creating the apex trigger on opportunity object that was sending email using apex code. This could have been done using workflow rule if the owner's manager was not invloved in the requirement, just because of one recipient we needed to write the code (It is not possible to implement with process builder also).


Recently, we got the same requirement and this time we decided not to implement this using the code and after a few attempts we made it possible using workflow rule.

Following are the steps to implement this requirement using workflow:
  1. Create a formula field on the opportunity object (or on any object as per your requirement) with formula return type as 'text', the formula field should reference to the parent's email field, in our scenario it should reference to email field of opportunity owner's manager. 
      
     
  2. Now, create the workflow email alert in which you want to add owner's manager as recipient and add any field/user/group as the recipient. We are selecting a user as recipient here.    
  3. Now go to the formula field that you created in the first step and note the field's Id. In our scenario it is 00N6F00000EY6mU. Please check below screenshot to locate this.
       
  4. Now inspect the recipient option that you selected in the 2nd step. For doing this right click on the recipient and click on 'Inspect'. After doing this you will see below screen.
      

  5. Now replace the 'value' attribute's value of the 'option' element that is highlighted in the above screenshot with 18:<email field's Id>, where "email field's Id" is the field Id that you identified in the 3rd step, in our scenario it will be "18:00N6F00000EY6mU".
     
  6. After completing above step, save the email alert and the task is accomplished. You will see that formula field has been added as a recipient in the email alert and it will work fine for this recipient same as it works for others.               

So after a few clicks and a small workaround, we can rid of writing a trigger for a simple requirement. Hope this will help you guys somewhere.

Happy Coding!!

Comments

  1. That is very interesting; you are a very skilled blogger. I have shared your website in my social networks! A very nice guide. I will definitely follow these tips. Thank you for sharing such detailed article.

    Best Project Management Software

    ReplyDelete
  2. Great blog.you put Good stuff.All the topics were explained briefly.so quickly understand for me.I am waiting for your next fantastic blog.Thanks for sharing.Any coures related details learn...
    Best Project Management Software

    ReplyDelete
  3. Great trick! Unfortunately it cannot be deployed in a change set.

    ReplyDelete
  4. Thanks for the informative article. This is one of the best resources I have found in quite some time.
    Nicely written and great info.I really cannot thank you enough for sharing.
    Reactjs Training in Chennai |
    Best Reactjs Training Institute in Chennai |
    Reactjs course in Chennai |

    ReplyDelete
  5. Hi @SFDC Drona. Great Trick! thanks for this. Is there a way to include record owner's email in the 'From Address' field on the email alert? Salesforce only provides current user's email, WF user email and other org wide email address to choose as 'From Address' in the email alert. So I was looking for a way to include record owner's email in the 'From Address' field on the email alert. I can use the same trick as above?

    ReplyDelete

Post a Comment

Popular posts from SFDC Drona

Retrieve IP Address for the Guest Users in Lightning Community