Email Button

  • 1
  • Question
  • Updated 2 years ago

I am trying to code a button to send to a email address in the open contact by opening the users default mail client on click and creating a new email to match a Salesforce email template.

I would also like to do the same type of thing for selected contact in list view.

Photo of Allison

Allison

  • 360 Points 250 badge 2x thumb

Posted 2 years ago

  • 1
Photo of Matt Small

Matt Small

  • 1,182 Points 1k badge 2x thumb
It is perhaps easier using a row action to direct using URL and  as you can see in this screenshot... 



As a URL we used this..

https://na11.salesforce.com/_ui/core/email/author/EmailAuthor?p2_lkid={{Contact__c}}&rtype=003&a...

Which will ultimately use the email function on salesforce by taking the end user straight to the page and then dumping the contact (Via contact ID) into the recipient field. 

I know it's not exactly what your looking for but in many ways this is a better option as it ensures that all the transactions remain contained on the Salesforce instance and you are not requiring to use an email client. 

Good luck and let me know how you go?
Photo of Allison

Allison

  • 360 Points 250 badge 2x thumb
Thanks.  We have to use the native email client (Outlook).  Any ideas?
Photo of Matt Small

Matt Small

  • 1,182 Points 1k badge 2x thumb
Could possibly write a .php snippet. I will keep looking into it =)
Photo of Bill McCullough

Bill McCullough, Champion

  • 12,436 Points 10k badge 2x thumb
Allison,

Try using 'mailto' in your button.  The sample below is the redirect URL of a button that belongs to a Page Title whose model is a Contact object.

mailto:?subject=Contact Information for {{Name}}, {{Professional_Suffix__c}}&body=%0D%0A%0D%0AName: {{Name}}%0D%0APhone: {{Phone}}%0D%0AMobile: {{MobilePhone}}%0D%0AFax: {{Fax}}%0D%0AEmail: {{Email}}%0D%0AAddress: {{MailingStreet}}, {{MailingCity}}, {{MailingStateCode}} {{Mailing_Zip_Code_Lookup__r.Name}}

Thanks,

Bill
Photo of Allison

Allison

  • 360 Points 250 badge 2x thumb

That worked.  Do you know how I could (1) insert contact's email in the To field, and (2) insert HTML into the body of the email?

Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
Have you looked into using Cirrus Insight or SalesforceIQ Inbox?
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
Additionally, seems like HMTL insert is impossible.

http://stackoverflow.com/questions/5620324/mailto-with-html-body

You can do some basic things like a adding a line break though.

http://stackoverflow.com/questions/11507387/mailto-body-formatting
Photo of Chandra V

Chandra V, Champion

  • 6,966 Points 5k badge 2x thumb
I did a quick POC on this a while back.  Here is the snippet I ran from my page, triggered by a button.  It produced an email open (using Outlook, native email client) and populated the Subject, To and Body.  You can also BCC or CC folks by just adding those to the url string.


var params = arguments[0], $ = skuid.$;

AcctModel = skuid.model.getModel('account'),
AcctRow = AcctModel.getFirstRow();
AccountId = AcctModel.getFieldValue(AcctRow,'Id',true);

ContactModel = skuid.model.getModel('contact'),
ContactRow = ContactModel.getFirstRow();
contactEmail = ContactModel.getFieldValue(ContactRow,'Email',true);

var subject = "This is my subject";
var email = contactEmail;
var emailBody = "Hello World ref:"+AccountId;

var url="mailto:"+email+"?subject="+subject+"&body="+emailBody;

window.top.location.href= url;