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[] {lead1.email};
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setTargetObjectId(lead1.ID);
mail.setSenderDisplayName(‘Salesforce Support’);
mail.setUseSignature(false);
mail.setBccSender(false);
mail.setSaveAsActivity(true);
mail.setReplyTo(‘[email protected]d5a.28-1ka01eac.ap6.apex.salesforce.com’);
EmailTemplate et=[Select id from EmailTemplate where DeveloperName=:’Testing’];
mail.setTemplateId(et.id);
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 = System.today(), ReminderDateTime = System.now(), 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

0 Comments

Leave a Reply

CONTACT US

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

Sending

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

or    

Forgot your details?