0

On the Standard Record page for a CustomObject__c, I want to display a button or link (Quick Action, URL formula field, ...) that when clicked by the user opens the users preferred email client with a pre-populated email (To, Subject, Body) ready to extend and send.

If I don't have to I am more than happy to not need Aura Components and Apex Controllers for that. So the less I need the better.

1 Answer 1

4

You can use a normal Formula field to do this:

HYPERLINK('mailto:'+EmailAddress__c+'?subject=Hello+There&body=This+is+an+example','Email Me')

For more information, see Email Links on MDN.


You can also make a quick action:


<aura:component implements="force:lightningQuickAction,force:hasRecordId" >
    <aura:attribute name="contact" type="Contact" />
    <force:recordData recordId="{!v.recordId}" targetFields="{!v.contact}" layoutType="FULL" recordUpdated="{!c.sendEmail}" />
</aura:component>

({
    sendEmail: function(component, event, helper) {
        var a = document.createElement("a"),
            contact = component.get("v.contact");
        a.href = "mailto:"+encodeURIComponent(contact.Email)+
            "?subject=Test%20subject"+
            "&body="+encodeURIComponent(contact.Description);
        a.click();
        $A.get("e.force:closeQuickAction").fire();
    }
})
5
  • Didn’t expect it to be that easy. Thought formula fields wouldn’t allow mailto hyperlinks. Commented Jun 5, 2019 at 14:51
  • 1
    @RobertSösemann Honestly, I didn't either, so I had to test it first.
    – sfdcfox
    Commented Jun 5, 2019 at 14:55
  • Naaah. Can't use that approach because the mail body must come from a Long Text field and those are not allowed in Formulas. I am also quite sure that the maximum length of URL parameters will restrict long email bodies. Commented Jun 5, 2019 at 16:03
  • Can you think of another "lean" solution. Maybe an Action component without Apex just using Data Services... Commented Jun 5, 2019 at 16:10
  • 1
    @RobertSösemann Added an example quick action version as well.
    – sfdcfox
    Commented Jun 5, 2019 at 16:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .