How to Capture Replies in Salesforce by using Email services?

How to Capture Replies in Salesforce Using Email Services?

When you are sending Email by using trigger then you have to implement these codes in your trigger -

String[] toAddresses = new String[] {};
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setSenderDisplayName(‘Salesforce Support’);
EmailTemplate et=[Select id from EmailTemplate where DeveloperName=:’Testing’];
Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});

Steps to create email service-

  1. Click on Setup
  2. Type Email Service on search box
  3. Click on new Email service
  4. Enter the name of Email service
  5. Choose the Apex classes -which is mentioned below
  6. Click on Active check box
  7. Create New Email addresses
  8. Click on save button .

Email services class

global class createActivity implements messaging.Inboundemailhandler {
    List <lead> leadlist;
    global messaging.InboundEmailresult handleInboundEmail(messaging.InboundEmail email, messaging.InboundEnvelope envelope) {
        leadlist = new list <lead>();
        system.debug('@@@@@email:' + email);
        system.debug('@@@@@envelope:' + envelope);
        messaging.InboundEmailresult result = new messaging.InboundEmailresult();
        string Activityname = email.fromname;
        system.debug('@@@@@Activityname:' + Activityname);
        String fromemailaddresss = email.fromAddress;
        List <lead> leadlist = [select id from lead where email = : fromemailaddresss limit 1];
        system.debug('@@@@@fromemailaddresss:' + fromemailaddresss);
        string des = email.plaintextbody;
        string tasksubject = email.subject;
        Task tkobj = new Task(Description = des, subject = tasksubject, Priority = 'Medium', ActivityDate =, ReminderDateTime =, WhoId = leadlist[0].id);
        insert tkobj;
        system.debug('@@@@@tkobj:' + tkobj);
        return null;

Note - 

Email Service Salesforce Developer Edition
Task Re Application Status Salesforce Developer Edition
Lead Rajan Salesforce Developer Edition

Popular Salesforce Blogs