I have created a new email service which populates a Lead__c field on the emailMessage object. Then i am displaying the emailMessages in a related list component. However, even though im getting the emails to show in the related list, i do not get the options to reply, reply all, or forward which i believed to be ootb functionality. I read an Article which stated: Users can Reply, Reply All and Forward if they are listed in the To, Cc or Bcc fields in the email (for example, is a recipient) or are the sender.

I attempted to hardcode my email in the BCCAddress field but these options were still not displaying for me. I have also tried creating an EmailMessageRelation record to tie the email to the lead but i am not having any success there either. I have posted what i believe to be the relevant portion of code below.

global class EmailToLeadEmailSvc implements Messaging.InboundEmailHandler {
    global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email,Messaging.InboundEnvelope env)
        // Create an InboundEmailResult object for returning the result of the Apex Email Service
        Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
            id leadId = email.plainTextBody.substringBetween('reference:{', '}');
            EmailMessage emObj = new EmailMessage();
            emObj.FromAddress = email.FromAddress;
            emObj.FromName = email.fromName;
            //emObj.BccAddress = 'MY EMAIL @ MY EMAIL .COM ';
            emObj.TextBody = email.plainTextBody;
            emObj.HtmlBody = email.htmlBody;
            emObj.Status = '0';
            emObj.Subject = email.subject;
            emObj.Lead__c = leadId;
            //emObj.RelatedToId = leadId;
            insert emObj; 

            EmailMessageRelation emr = new EmailMessageRelation(
                EmailMessageId = emObj.id,
                RelationAddress = leadId
            insert emr;

I would love to be able to see these emails in the standard activity timeline for easier visibility/standard functionality but i have not been able to achieve that.

  • Update: i have now been advised/researched and found that to link an email message to a lead you must set the field ToIds to the id of the record instead of setting the ToAddress field. However, i am still having issues viewing the Reply/Reply All/Forward buttons and i am listed as a recipient and/or sender of these emails. – Logie C Dec 19 '19 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.