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’);
mail.setReplyTo(‘[email protected]’);
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 EditionTask Re Application Status Salesforce Developer EditionLead Rajan Salesforce Developer Edition


Leave a Reply


We're not around right now. But you can send us an email and we'll get back to you, asap.


About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2018 Forcetalks. All Right Reserved.

Log in with your credentials


Forgot your details?