Email Services Apex Class in Salesforce: Contact Handling and Extraction

A primer on the Process

For the uninitiated, the Email Service in Salesforce is an automated Process that strips content bodies, subtext, headers, and attachments from inbound emails for Object creation.

 

You could go about tieing each Email Service Process to Salesforce-created email addresses meant to receive messages for processing from users of a service.

 

Alternatively though, to give multiple users access to a service you could associate a single Salesforce email to an Email Service and write a class in Apex to execute differently for each user.

A common use case

As an example, you could write Apex Classes to identify users based-off of their email addresses and create Records accordingly.

Let’s talk Governor Limits

As is often the case with email capabilities, there’re Governor Limits to keep in mind. Here’s a list of them:

 

  • An email service only processes messages it receives at one of its addresses.
 
  • Salesforce limits the total number of messages for all email services combined for daily processing, including On-Demand Email-to-Case. Messages exceeding this limit are bounced, discarded, or queued for processing the next day, depending on how you configure the failure response settings for each Email Service.

Salesforce calculates the limit by multiplying the number of user licenses by 1,000 and caps out at 1,000,000. For example, if you have 10 licenses, your Org can process up to 10,000 email messages a day.

 

 

  • Email Service addresses created in your sandbox can’t be copied to your production Org.
 
  • For each Email Service, you can tell Salesforce to send error email messages to a specified address instead of the sender’s email address.
 
  • Email Services reject email messages and notify the sender of the email(comprised of combined body text, body HTML and attachments that extend approximately 10 MB depending on language and character set).

Now that you’re a bit more familiar, here is some syntax for you to look at. First of these – is the Email Service.

General syntax for Email Service class in Salesforce

Some more syntax

For our example, we start with the premise that each email’s subject and body contain no more than the words “Create Contact” and the Contact’s name(in that order).

 

Then, in the likeness of an everyday enterprise scenario, we process subject lines to create new Contacts in Salesforce and extract Contact Names from the email body. Attachments come up under the Contact object in sales.

 

In the following sections, you’ll find code implementations and test classes( 75% coverage) for the same.

Apex Class:-

Test Class:-

Defining Email Services with our Apex Class

 

After creating the above Apex Class, within your instance, go to

 

<Your Name> | Setup | Develop | Email Services.

Once there,

 

  • Click New Email Service to define a new Email Service.

Select the Apex Class we just created above, add the email address from where to accept the request and activate the Service as shown below:

After filling out the information, click Save and New Email Address

Next, click Save. This should throw up an email address as shown below.

Note: The domain name in the Email Address must qualify the one entered at Email Service in the first step. For instance, we’ve entered “gmail.com” in the first step, which means it will accept the email address only from gmail.com like the one in the email we just saw.

 

Finally, once the email address is generated by Salesforce, send the email to that address with the subject line “Create Contact” and a Contact Name as the email body to see if everything checks out.

Conclusion

The codebase here lets you extract data from emails for creating Contacts in your Salesforce Org that could be used to service Contacts from a business account in case of multiple users, especially for helpdesk operations or pushing updates and notifications. You could just as well extend this to build on stores for other objects. For any further assistance with Email feature sets or data extraction solutions for the Salesforce platform, don’t wait to reach out to us at sales@hicstwebackup.yoursalesforcedeveloper.com

Share This Blog
Related Articles

Salesforce CPQ (Configure, Price, Quote) is a powerful tool that enables businesses to streamline their quoting process by providing advanced configuration options. Among its many features, Multi-Dimensional Quoting (MDQ) stands out as a powerful capability that allows sales teams to create more detailed and flexible quotes for complex products. In this blog, we’ll dive into […]

Read More
Dynamic Search Filters in Salesforce CPQ

Salesforce CPQ (Configure, Price, Quote) is a powerful tool that allows sales teams to generate quotes with speed and accuracy. One of the key features that makes CPQ so flexible is its dynamic search filter capability. In this blog, we’ll explore how you can create dynamic search filters in Salesforce CPQ to make your quoting […]

Read More
How to Create Quote Templates Customization Methods

The objective after completing a quote is usually to produce a precise and expert quote document for clients. However, without the proper procedures in place, quoting can be difficult, error-prone, and time-consuming. Salesforce CPQ (Configure, Price, Quote) streamlines the process and improves quote accuracy by assisting with the setup and administration of quotation papers. By […]

Read More
Boost Performance with a Robust Trigger Framework in Salesforce

Boost Performance with a Robust Trigger Framework in Salesforce If you want to make sure of scalability and performance in the Salesforce development, managing Apex triggers is a must. With a trigger framework, you get a structured approach to organizing and maintaining trigger logic. This way, developers can follow the best practices while maintaining the […]

Read More

When it comes to Salesforce development, efficiently managing and deploying metadata is important to maintain streamlined operations. With the help of Unlocked Package, you can easily achieve this. It is specially designed for business’s internal use and allows businesses to develop and manage modular applications. This blog will walk you through the importance of Unlocked […]

Read More
How Salesforce Data Cloud Streamlines Data Management

The Data Cloud integrates your company’s data onto Salesforce’s Einstein 1 Platform. It provides each team with a comprehensive customer view for a better experience. The Data Cloud consolidates disparate data sources into a unified model, facilitating easy access and comprehension. It encompasses various data types such as web engagement and more from both internal […]

Read More
Our Location worldwide
Indian Flag India
3rd Floor, A-10, Pegasus Tower, Sector 68, Noida, Uttar Pradesh 201301 +91-1203117884
United States of America Flag USA
333 West Brown Deer Road Unit G – 366 Milwaukee WI, USA 53217 +1(262) 310-7818
United Kingdom Flag UK
7 Bell Yard, London, WC2A 2JR +44 20 3239 9428
Canada Canada
HIC Global Solutions INC
43 Lafferty Lane, Richmond Hill, L4C 3N8, CA +1(262) 310-7818