I have a scenario Like. From lead object through activity email is sent to customer if customer replies to that email i have to show that reply in activity of that particular record in lead object.can u please help me in solving the issue with out third party apps.I have tried with einstein capture but when same email id is used for different records both the data in mails is coming in both records which have same email id.


1 Answer 1


To achieve this functionality of displaying customer replies in the activity of the corresponding lead record in Salesforce, please follow below

  1. Enable Email-to-Case or Email-to-Lead: Salesforce provides a standard feature called Email-to-Case or Email-to-Lead, which allows you to automatically create cases or leads from incoming emails. You need to enable this feature in your Salesforce org and configure it accordingly.

  2. Set up Email Services: Email Services in Salesforce allow you to define an email address that can receive incoming emails and process them using Apex classes. You can set up an Email Service that will handle the incoming customer replies.

  3. Create an Apex Class: Write an Apex class that will be associated with the Email Service. This class should extract the necessary information from the incoming email and create an activity record on the corresponding lead object.

sample code

global class LeadEmailHandler implements Messaging.InboundEmailHandler {
    global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
        Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();

        // Extract necessary information from the email, such as sender, subject, body, etc.
        String senderEmail = email.fromAddress;
        String subject = email.subject;
        String body = email.plainTextBody;

        // Use the extracted information to find the corresponding lead record
        Lead leadRecord = [SELECT Id FROM Lead WHERE Email = :senderEmail LIMIT 1];

        // Create an activity record and associate it with the lead record
        Task activity = new Task();
        activity.Subject = subject;
        activity.Description = body;
        activity.WhoId = leadRecord.Id;
        activity.WhatId = leadRecord.Id;
        activity.OwnerId = UserInfo.getUserId();

        // Insert the activity record
        insert activity;

        return result;

Please let me know if you have any doubt

  • Hiee gopal I will try this scenario what you have explained can we connect through zoom or any means so that u can guide me thanks in advance
    – AdityaSD
    Jun 30 at 16:11
  • @AdityaSD it's very easy please try the same as I wrote in the example it will work, if it doesn't work you can share the issue here I will be happy to help!!
    – Gopal
    Jul 2 at 11:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .