Log an activity when firing a workflow email alert - Answers - Salesforce Trailblazer Community
Trailblazer Community
Ask Search:
Pete FifePete Fife 

Log an activity when firing a workflow email alert

This is a topic of great discussion from 2007.  See idea:
  •  
I know of two work around methods:
  1. create a completed task at the same time with the same subject as the email.
  2. utilize salesforce to email function.  This solution was given by SimonSmith on the Dev Boards
So here's the workaround[#2]:
  1. Duplicate the email template that you're using for the outbound email
    For example, we created a template called "Leads: Auto-Introductory Email to Leads" and a second one called "Leads: Auto-Introductory Email to Leads FOR ACTIVITY HISTORY"
  2. Somewhere in the duplicated template, "ref" the ID of the record for which you want to track the activity
    For example, in our duplicated template, we added ref: {!Lead.Id}
  3. Duplicate the original email alert, make it send ONLY to the administrator's Email-to-Salesforce address, and use the duplicated email template with the "ref" in it
So basically, here's what happens.
 
Someone enters a record in Salesforce that triggers the workflow rule.
 
The workflow rule triggers and sends both email alerts. The first alert gets sent to the recipient, in this case a lead. The second alert gets sent directly into Salesforce using the Email-to-Salesforce address. Salesforce then reads the "ref:" tag and assigns the email to the correct record. 
 
Of course, there are some caveats here.
 
The biggest is that each user has a different Email-to-Salesforce address, so if you want an email sent from different users to be recorded, you might have problems. But if you only care about having the email itself recorded, or want the email to come from a single address anyway, this workaround works.
Nik PanterNik Panter
That is a great idea.  I have voted it up.
Chaplain TIG HeasletChaplain TIG Heaslet
Simple and effective... perfect! Thanks Pete for posting.
Thomas GrunewaldThomas Grunewald
Thats a nice workarround. Thank you. I have been so far creating a completed task by the workflow that contained a short information that the e-mail was send. However we never had the e-mail content visible with this solution ;)
Manisha ChhodaManisha Chhoda
You can do it by apex or try chatter action.
Georgie RebaneGeorgie Rebane
It is a great work around. But as you have to use an email field for the "To" in the email alert, did you set up a user just for this with the admin's Email-to-Salesforce as the email address? Or do you use the admin's email address for the "To" and use the Email-to-Salesforce in the Additional Email field
John BivonaJohn Bivona
In my situation I wanted to record the workflow email alert from a case AND I already have an email to case email address within SFDC AND the outbound email from the workflow was being sent to internal users, so to cut some corners I just added the unique email to case email address to the cc: of the outbound email and added the ref: {!Case.Id} as described by Pete.  
Sebastien RousseauSebastien Rousseau
Hi John,

I have the same need as you and it doesn't work. I added the {!Case.Id} field in my email template and copy the email-to-case address to additional emails. On closing case, emails are well sent but no history activity are log to the case.
Did you get some workaround to make it work?

Thanks in advance
Seb
System AdministratorSystem Administrator
 My customer needed this functionality (I agree it seems lame that you can't do this as an option to Email alert....LOG THIS!) So, while this solution has some issues....here it is: I added a field called Template ID to the Lead Record(in this case) and have a workflow that upon the given event will set the ID in the template Field to the correct template. Then we wrote a trigger that inspects the Template ID field..if it is set it uses APEX to send the HTML email. This gives both a LOG of the event and lets you know if the Lead/Contact has read it, Email Bounces etc. Once it is sent, it deletes the Template ID field value. 
Backoffice IntegrationBackoffice Integration
Does second solution works for anyone? It doesn't seems that it would cause there is no BCC field in which you can enter  Email-to-Salesforce address. Also you cannot set this address for user cause it has to be verified.
Pete FifePete Fife
Mr or Mrs Backoffice Integration user - yes the second solution does work for anyone.  A subtle and key point made in the reference dev blog is the email goes in the CC line and you must not mind the person receiving the email will see this long salesforce email.
Backoffice IntegrationBackoffice Integration
Its MR :) Thanks for quick answer. I've set user (which is admin with my email) to receive email and in additional emails I've put Email-to-Salesforce address. I've received email but it is not showing in Activity history. Can you please advise? Also I have ref: {!Lead.Id} added to the email.
Pete FifePete Fife
Hum... well with out testing and going through it all, I'm not sure, sorry. 
Backoffice IntegrationBackoffice Integration
Finally I got it. 

I had to turn off "Advanced Email Security Settings" in Setup -> Email to Salesforce. It is a little bit strange cause it is an email sent from Sales Force sandbox.

Also email will be attached via ref: {!Lead.Id} and also via email in TO field (this is email of user which is selected to be recipient, in my case it is sys admin). If SF cannot find any lead/account/contact with email from TO field it will put this email into Unresolved items.

Hope this will help to other users trying to setup this.
Sanjeev RandhirSanjeev Randhir
All, I have a same requirement-to capture a email fired through workflow and need to capture it in the Opportunity Activity History.

I need to understand what exactly we need to use in Additional Emails field- any specific Salesforce email address or just Email-to-Salesforce? in case if it is Email-to-Salesforce address what it should be or I need to create it?
Appriciate your help!
Support IntertraderSupport Intertrader
You have to use Email-to-Salesforce email address.

See following text from SF help: 

"An administrator must activate Email to Salesforce for your organization. After activation, Salesforce generates a unique Email to Salesforce address for each user. Users receive an automated email from Salesforce that contains their Email to Salesforce address. Users can view their Email to Salesforce address in their personal settings under Email | My Email to Salesforce. The Email to Salesforce address is automatically generated and cannot be changed."
Ashley Braun SistiAshley Braun Sisti
Is there any way to do this if the email is coming from an email address that is set up as an "org-wide" email address? There's no specific user tied to that, so there's no user's email to salesforce email address that will work - it doesn't recognize the sender as matching the email-to-salesforce user. 

Also, we're trying to do this for cases - I'm basically trying to replicate the auto-responder for cases that are created via an automated process, but for any case creation, including manual. If I include the case Id in the email, will it automatically log to the case as well as the contact?
Birthe OelmannBirthe Oelmann
Hi Guys

I have set this up as well but unfortunately I get an email sent to the activity history (which is great) AND an email is put into Unresolved Items (this is not great).

Does anyone know why this is? I set the email alert to only send to the email in the additional emails section where I put my admin BCC email address, is that not the right place?

Thank you

B
Christina MooreChristina Moore
I used this today and it worked like a champ!  

Thanks for the save!
José CorreiaJosé Correia
I've done exactly what was written above and it didn't work. Should I insert in the recepient type the system administrator? Because I did it and it didn't work. The email didn't get registered into the lead activity.
Karan KamraKaran Kamra
Hi All,
You can use a trigger to get this functionality. Here I am recording the Activity History for email sent to a contact.
Note: I have created a custom field on contact called Task Notification Sent in order to achieve the same.

/*
   Trigger for Email Alert for contact and recording the same in Activity History
*/
trigger ContactTriggerForEmailAlert on Contact (after insert,after update) {
    List<Task> followupTasks = new List<Task>(); // Build list in memory
    Set<Id> newcontactIds = new Set<Id>();  //RecordCount for Contacts in the Set
    List<Contact> cList = new List<Contact>();
            
       for (Contact con : Trigger.new) {
            if(trigger.new.size()>=1) {
               newcontactIds.add(con.Id);
            }                             
       cList = [Select Id, Name, OwnerId, Task_Notification_Sent__c, Email from Contact where Id IN: newcontactIds];             
       EmailTemplate Et = [SELECT Id FROM EmailTemplate WHERE Name = 'Task_Notification'];      
       
       for (Contact con1: cList){                        
         if(trigger.isinsert && con1.Task_Notification_Sent__c == false || trigger.isupdate && con1.Task_Notification_Sent__c == false) {                       
                if (con1.Email != null){
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                String[] toAddresses = new String[] {con1.Email};
                mail.setToAddresses(toAddresses);
                mail.setBccSender(false);
                mail.setTargetObjectId(con1.id);
                mail.setSaveAsActivity(true);
                //mail.setSubject('subject');
                //mail.setPlainTextBody('templateBody'); // Using the Email Template created instead
                mail.setTemplateId(Et.Id);
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});     
                con1.Task_Notification_Sent__c = true;
                update con1;    
           }
        }   
      }
    }
}
Steve GoffSteve Goff
Do you have to the ref: {!Contact.Id} in a certain place? I tried putting it into the subject and also the body of the email alert. I also didn't know how to make the email alert go to that email to salelsforce address? I placed it into the 5 additional addresses box but that doesn't seem to work.
 
pavan kumarpavan kumar
Hey @Pete Fife  I tried your way on case object with mentioned case id in duplicate template like {!Case.Id}.But no activity has been created in related object.Please can you tell me where i did do wrong.
Pete FifePete Fife
Hey Pavan - Well I'm not sure this is working anymore.  From the other posts it seems that this may of stopped.  Case's should have thread id you should use.

In my post you need to be sure you include the key word ref.  Example:  "ref:{!object.id}:ref"

But if you're on cases, you should use the built in thread ID field.
pavan kumarpavan kumar
Hey @Pete Fife thanks for your reply.I tried using thread id in email template like ref: {!Case.Thread_Id} and with out ref also & even i tried including with in subject line also it is not working.

Did i forgot anything or it's not working.Please can you look on this.
Cynthia SmithCynthia Smith
Hi @Pete Fife. I have the same question as @Steve Goff 

"Do you have to the ref: {!Contact.Id} in a certain place? I tried putting it into the subject and also the body of the email alert. I also didn't know how to make the email alert go to that email to salelsforce address? I placed it into the 5 additional addresses box but that doesn't seem to work."

We created a workflow to automatically send a thank you email to our donors when they make a gift, but it doesn't record it in the Activity History for the donation/opportunity. I tried the workaround with the opportunity ID, but it isn't logging the email. I, too, wasn't sure where to put the ref:. Any ideas why it isn't working? We are using the NPSP. 

Thanks,
Cynthia
Yiannis GaitanosYiannis Gaitanos
Hi guys,

I think i have a workaround using the Email to Salesforce functionality which seems to be working ok for now. No need for duplicate email templates etc.

1. Create your HTML email template to send via the workflow. Make sure to include "ref:{!Lead.Id}" somewhere in your email. (if you do not want your clients/customers to see this, simply colour the text the same as the background using CSS and/or make font-size very small e.g. 1px

2. Create your email alert workflow using the email template you want to send and in the Additional Emails textbox paste in your Email-to-Salesforce email address.

3. Test your workflow.


The idea behind it is that in the email CC'd to your Email-To-Salesforce address, Salesforce can detect the Lead's email address and their Lead ID and therefore associate it. 

Seems to be working for me for now, so give it a try :)
Charlotte NeveCharlotte Neve
Thank you Thomas! Your workaround worked perfectly for me, although my workflow was based on a custom object. Custom object has a 1:1 relationship with a contact, which allowed me to include the contact ID to the email template. When my workflow fired the email, the email was added to the contact and the account. So awesome. This made my day!
Kimberly LovelandKimberly Loveland
@ThomasdeLucy - this is working like a charm for my Cases, but I can't get it work for my Contacts. I was hoping to get the email alert to copy to both my Activity for the Case and the Contacts. Am I pushing it? (ha) I've added both the ref: for the CaseID and the ContactID and then added the email-to-case email address and my email-to-salesforce address to the additional email box on the alerts. Thanks for any help you can provide! 

This has already been a huge help!!! :)
arun sharmaarun sharma
Hi, Can anybody pick this up! 
I have the same scenario but for the Orders. I can see through the Activity Log is generated for Lead and Contacts.
Can somebody guide me how to work this out when Workflow email alerts to Orders should be recordable as activity history.

Thanks in advance!
Ben PattersonBen Patterson
I see process builder can create an email message now.
Vikram SinghVikram Singh
Hey @Pete Fife  I tried your way on a custom object as mentioned in duplicate template like ref:{!object.Id}, but no activity has been created in related object.
FYI, if i chose Contact as "Automatically assign them to related salesforce.com records" under "Email to Salesforce" with the ref:{!object.Id} then it goes to My Unresolved Items, which is because of id mismatch between Contact and my Custom object and understandable. Moreover i can manually assign this task to that particular object record.
My concern is if i don't chose Contact (or any option) then why salesforce is not reading the ref: tag and assiging this task directly to my Object record like i did for above case manually. It should, right. Please can you tell me what i am missing?
Any quick help is appriciable.
Pete FifePete Fife
@Vikram - it appears my suggestion from 6 years ago no longer works.  Therefore I would utilize this method now written up by Jen Lee: Log an Email Sent via Email Alert to the Activity History

https://jenwlee.wordpress.com/2017/07/11/log-an-email-sent-via-email-alert-to-the-activity-history
Keith KelleyKeith Kelley
@Yiannis I have tried your method multiple times, it seems like it will work. but I have still not logged an activity. this is the code I'm using in the body of my email:"ref:{!Contact.Id}"  should it be in the subject line? 
 
Jay @ CRMJourneyJay @ CRMJourney
There is a solution out there. Please check this out. 
Activites Pro - Capture Workflow and Email Alerts as Activities in Salesforce (#)
Jay @ CRMJourneyJay @ CRMJourney
https://timelineiq.com/salesforce-activities-tasks-events-field-history-tracking-round-robin-voice-initiated-tasks-salesforce.html
Siva DevakiSiva Devaki
You can do this using massmailer.io feature through which you can send email alerts to contacts or leads and  log as an activity history. You can also track the emails such as open, click, spam, unsubscribe etc. You can go through this article (http://support.massmailer.io/support/solutions/articles/16000076111-how-to-send-log-track-email-alerts-through-process-builder-using-massmailer) to learn about it more. If you need any help, just submit a support ticket at support.massmailer.io
Sunil ShahSunil Shah
Thank you Pete Fife :)
Daniel HowellDaniel Howell
Here is a free simple app that you can use in process builder or flows that sends emails and logs activity.

Here is the listing: https://appexchange.salesforce.com/appxListingDetail?listingId=a0N3A00000FMWT8UAP
Instructions: https://gravitylab.nz/send-email-alerts-and-log-the-email/

Please Salesforce still address this issue and make it standard (with the option to choose to log or not). Idea here: Workflow email alerts to contacts should be recordable as activity history (https://success.salesforce.com/ideaView?id=08730000000BroKAAS)