Add Gmail to Salesforce functionality in your email fields

This tutorial shows you how to integrate Gmail custom button functionality into any email field. In this example, we’re working on a Contact Tab Page and will add a Gmail to Salesforce link in an email template field, but you can use this template for any email field in Salesforce . This link will open a Gmail Compose window in a new tab and automatically enter the contact’s email address in the “to” field, and the running user’s personal Email to Salesforce address in the “bcc” field.

First, Email to Salesforce must be set up for all users.

image0

Go to Your Name > Setup > Email > My Email to Salesforce, add a new Acceptable Email Address and click Save.

  1. Click Your Name > Setup.
  2. Cick Email > My Email to Salesforce.
  3. Add your gmail address to My Acceptable Email Addresses.
  4. Modify the Email Association settings if desired, and then click Save.

Step 1: Click Add Model.

image1

A. Name your model “EmailToSF” and choose EmailServiceAddress as the SObject Type.

image2

B. Add the fields “Email address” and “Email address domain” into your model.

image3

  1. Click Fields.
  2. Check the fields Email address and Email address domain.

Step 2: Click Conditions, and click to add three new conditions.

image4

  1. Click Conditions. Click to add a new condition.
  2. Click on the first New Condition to edit it.

Step 3: Set the first condition’s field to “RunAsUserId.”

image5

Click on the field icon and then search and select RunAsUserId from the field list.

Set the value to “User Id of the user running this page”

image6

  1. Click Value.
  2. For Content, select UserInfo of page viewer. The property will be set to “User Id” automatically.

This condition ensures that the model pulls in Email to Salesforce information specific to the user running the page.

Step 4: For the second condition, create a condition that will only pull in Active records.

image7

  1. Click on the second condition.
  2. For Field, select IsActive.
  3. Click Value and click the checkbox for “true.”

Step 5: Set the third condition to the FunctionId > FunctionName field.

image8

  1. Click on the icon to select a field.
  2. Click on the green arrow to dive into the Service related fields.
  3. Search and select Email Service Name (i.e. FunctionName).

Set the Value of this condition to “EmailToSalesforce.”

image9

Now this model will only pull in records where the Function Name is “Email to Salesforce.”

Step 6: Pull a template field into your table or field editor.

image10

Step 7: Name the template, click to Allow HTML, and copy-paste this template into the Template area.

image11

Basically, this template says “if there is an email field for this Contact, include this link to Gmail that will send an email to your contact and bcc this user’s personal Email to Salesforce address.” Substitute the name of your model for EmailToSF, and the appropriate Email field (e.g. Contact.Email, Email2__c — you can use the field picker if you don’t know its name) for Email and copy and paste this template it into the Template field:

{{Email}}{{#Email}} [<a href="https://mail.google.com/mail/?view=cm&fs=1&tf=1&to={{{Email}}}&bcc=emailtosalesforce@{{#$Model.EmailToSF.data}}{{EmailDomainName}}{{/$Model.EmailToSF.data}}&shva=1" target="ComposeGmail"><img src="/img/google/gmail_M_icon.gif" alt=""/> Gmail</a>]{{/Email}}

Note

This template will work as long as you have Gmail set up. If you are using a different email service provider, you will need to use different URLs and should probably include a different image .

Step 8: Click Save and then Preview.

image12

Success! You will be taken to Gmail’s “Compose Mail” page in a new tab.

image14

Notice that the Contact’s email is in the “To” field, and you (the user’s) personal Email to Salesforce address is bcc’d. This means that this email will be associated to this Contact’s record in Salesforce :)

If the bcc address is only “emailtosalesforce@” with no domain name, you’re probably experiencing one of the two following errors:

  1. The email address wasn’t included in your main model (Contact, Lead, etc.). Go back and make sure it’s included.
  2. The page can’t find the domain name in the Email Service Address model, because when you copy and pasted the template in Step 7, you didn’t change EmailToSalesforce.data to YourEmailServiceAddressModel.data.
  3. You haven’t set up Email to Salesforce in your profile yet. See the instructions below.