Email to Post for Chatter

Posted on 27 June 2014 by Paul Weeden

With Salesforce being an integral part of our service delivery, we wanted to use Chatter to communicate both internally and with our clients through a single, integrated medium. The platform has some powerful features, yet lacked a message automation capability, which formed the focus of our latest Labs workshop.

Our research led to the development of "Chatter Email to Post", which allows administrators to configure pre-defined, templated, contextually rich text posts to the Chatter Feed of any record by harnessing the power of Salesforce's native workflow engine.

What It Does

You can now create Chatter Posts directly from your existing workflows and business processes which are immediately accessible and actionable from anywhere on any device.

How It Works

Email to Post for Chatter uses Email Templates in conjunction with Email Alerts and Apex Email Services to provide business process, workflow driven updates to Chatter Feeds without having to write complex code or re-engineer / re-create your workflows in 3rd party applications.

You simply need to create email templates and alerts which are sent as part of the normal workflow execution process.  Instead of sending these emails to a person, you send these emails directly to the Chatter Email to Post engine which processes the email and creates a Chatter Post, complete with @Mentions, #tags and links.

Posts made using Chatter Email to Post with @Mentions are automatically sent through to the Salesforce1 App using the built-in notification framework.

Quick Start

To get started, you need to install the application from the AppExchange and follow these steps.

NB. You must have Administrator access to install the AppExchange package.

Installation Steps

  1. Install "Chatter Email to Post" from the AppExchange.
  2. Create a Public Group with no members called "Chatter Email to Post - No Reply".
  3. Create an Email Service called "Chatter Email to Post" and set the Apex Class to "chatterEmailToPost_emailHandler" and click "Save and New Email Address".
  4. Create a new email address for the Email Service you created in step 3 and copy this email address to the clipboard as you will need it in step 5.
  5. Edit the Email Alert called "Chatter Email to Post - Test Post":
    1. Remove the recipient "Case Owner" and replace with the Public Group "Chatter Email to Post - No Reply" you created in step 2.
    2. Paste the Email Service email address you created in step 4 into Additional Emails field.
    3. Ensure the From Email Address is set to "Current User's Email Address".
    4. Save the Email Alert.
  6. Activate the Workflow Rule "Chatter - Email to Post - Workflow".
  7. Find a case, edit the case and 5 - 10 seconds after you save the case, the content in the Email Template will appear on the Chatter Feed of the case.

Now you are all set to create your own Chatter Posts as part of your workflow processes.  An example to the email template and more information on the template syntax is included below.

Email Template

To create a Chatter Post on a record using the Chatter Email to Post engine, you need to create a plain text email template.  The Email Template can use any Merged Field from the target object and User or Contact.

For the purpose of this example we have used a plain text email, however it would be possible to use Visualforce Email Templates to create even richer Chatter Posts.  For Visualforce Email Templates you must use the field plainTextBody.  

Example Template

The email template below creates a public Chatter Post on a Case which is visible to all users (both internal and community users). This template is included in the AppExchange package.

This email template with line identifiers:

#subjectId {!Case.Id}
#visibility AllUsers
#feedType Record
#postText This is a public post which mentions a User
#atMention {!Case.OwnerId}
#postText and uses the Merge Field: Case Number "{!Case.CaseNumber}"
#postText and follows up with a URL
#postText and a hashTag
#hashTag simple

Please note that the #lineIdentifiers are case sensitive

Results in a Chatter Post like this:

Chatter Email to Post Example

The Chatter Post is constructed based upon the order in which you enter the values #postText, #atMention, #URL, #hashTag in the email template.  There are no limits as to how many times these can be used, but the final chatter post must be between 1,000 and 5,000 characters, see Salesforce documentation for full details.

Line Identifiers

The "Chatter Email to Post" processes the plain text email body of an email and only accepts the following Feed Control and Feed Value line identifiers.  Please note that the line identifiers are case sensitive.

Feed Control

Line Identifier Description Permitted Values Required
#subjectId This should be the Id of the record you wish to post the feed message to, or the values as determined by the postFeedItem documentation See Documentation Y
#visibility Sets the visibility of the post to either Internal users (Default) or all users with access (i.e. make it visible to partners / community users).  See here for more information. If you do not specify AllUsers when using #communityId or #dynamicCommunity then the post will not be visible to any community / external user. Internal / AllUsers N
#feedType Sets the type of feed you are posting to.  Default is Record.  See postFeedItem documentation for more details. Record / UserProfile / News N
#communityId Default value is null, can be the Id of the community you want to post the message to. Community ID N
#dynamicCommunity Specify this value is you want the post engine to determine the community dynamically based upon the @mentionUser n/a N

Feed Value

All Feed Values are extracted from the email body, the line identifier value removed and any trailing spaces are removed to avoid any double spacing in the post.  The engine then adds a space before each section to ensure all words are evenly spaced.

Line Identifier Description Permitted Values Required
#postText This is the message text Any text N
#atMention This is the Id of the user you want to @mention A User Id N
#URL The text of the URL.  You do not need to add http[x]:// Any text N
#tag The text which makes up the hash tag.  Do not add the # prefix Any text  N

The email must contain all of the required Feed Control values and at least one Feed Value for a post to be created.

More Information

If you have any questions please get in touch with us at Twitter / Facebook / LinkedIn

Subscribe to Foration’s Blog Posts by Email