Quick win 5. Saleforce Service Cloud Email services and My email to Salesforce features

Itsmem0h1t
3 min readFeb 23, 2021

--

Lets see them both -

  1. Email Services (what, why and relevance)
  2. My email to Salesforce.

Email Services — is a feautre that let’s you handle & define automated processes as soon as the email hits your salesforce instance.(salesforce Org.) It uses Apex classes to process the contents, headers of the email, and attachments of inbound email.

For example, We can create an email service that automatically creates contact/ case (any Object) records based on contact information in messages. OR create / log a task (activity record) as soon as the external system processes something and you wanted to record that as an activity under Salesforce.

e.g: 3rd party services snding an email w/wo attachments to transfer the data and you can log this in Salesforce using Email services. Also another area is at times, if you have a SFMC instanc (SF marketing cloud), you can do a “bcc” from your journey builder to log intercation as activity record under SFDC CRM.

P.S: Each email service has 1 or more email service addresses that can receive messages for processing.

External user / system triggering an email to Email service exposed from Salesforce reults in exeuction of your busines logic (CRUD)

Steps to execute:

  1. Go to Setup → Email services →New email service

2. Use the code from below to log a task as soon as the email hits email service.

global class CreateTask 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();

String myPlainText= '';
myPlainText = email.plainTextBody;

// Create a new Task object
Task[] newTask = new Task[0];
try
{
// Try to look up any contacts based on the from email address.
Contact vCon = [SELECT Id, Name, Email FROM Contact WHERE Email = :email.fromAddress LIMIT 1];

// Add a new Task to the contact record we just found above.
newTask.add(new Task(Description = myPlainText,
Priority = 'Normal',
Status = 'Inbound Email',
Subject = email.subject,
IsReminderSet = true,
ReminderDateTime = System.now()+1,
WhoId = vCon.Id));

// Insert the new Task
insert newTask;

System.debug('New Task Object: ' + vCon.name+vCon.id);
}
catch (QueryException e) {
System.debug('Query Issue: ' + e);
}
result.success = true;
return result;
}
}

3. Last is to create some dummy or busines given email addresses under email addresses related list

Next, My email to Salesforce →lets you enter the Email to Salesforce address in the BCC line of emails that you want to add to the activity history of related records.

To view this go to Settings, under your user icon (right side) → Email → My email to Salesforce

Salesforce generates this email address automatically. and when you bcc an email to tis email address it gets logged undr Salesforce using the criteria you define.

P.S: If you are unable to find this that means email to SF is not enabled , you need to do that prior by going as depicted below:

Where is this used → this is a nice addon used in the sales where sales advisors while on the transit can just do a Bcc to log email from customr inside Sf. They dont need to login to SF.

Also you have the possblity to define the acceptable and exclusion list as well for th email addresses.

thanks — Mohit

--

--

Itsmem0h1t
Itsmem0h1t

Written by Itsmem0h1t

Program Architect at Salesforce, 27x Certified

No responses yet