Skip to content Skip to main navigation Skip to footer

Using Email To Field in Document Action

The “Email To” field in Document Action must result in providing either a Contact Id or Lead Id. This could be the API field name of a contact or lead lookup field that’s located on your base object. With using Opportunity as base object example, the merge field should be in a format like {!Opportunity.Primary_Contact__c} where you put the API name of the field within the curly brackets. The provided custom button/link code provided below assumes this field is a lookup field and adjusts the merge field to be appropriate for a button code merge field which is {!Opportunity.Primary_ContactId__c} in this example.

You can use the “Here” link within help text below email section in document action to go custom button configuration to select your base object and the API name of lead or contact ID to create the proper merge field format as mentioned above.

See this example image for how to create Email To merge field from custom button (using Opportunity base object as example):

Using hardcoded Contact/Lead Id for Email To:

You can hardcode a Contact Id or a Lead Id without any problems or additional steps. Both 15 and 18 character Ids are allowed. Just paste the code to custom button URL. See screenshot below.

Using Formula field for Email To:

Default value that the Email To field expects is a lookup to contact or lead. For those fields, the app is automatically adding Id part in the API name of the field you provided, as stated above. Since the app expects lookup fields, it’s adding the Id part even if the provided field is not a lookup. In that case, the Id part should be removed manually when pasting the code to custom button URL.

For example, let’s say we have a formula field on Opportunity record, which stores the Contact Id, with API name Contact_Formula__c. You would populate the Email To field with this string: {!Opportunity.Contact_Formula__c}, and the app would generate the code like this: {!Opportunity.Contact_FormulaId__c}. When pasting the generated code in the custom button URL, you would just remove the Id from the button code that looks like this: emailTo={!Opportunity.Contact_FormulaId__c}, making it to look like this: emailTo={!Opportunity.Contact_Formula__c}, as seen in screenshots below.

Same applies for any field type other than lookups. Id part is automatically added, and it just needs to be removed when pasting the code.

Configuring Email To for Apex, batch or trigger automation:

If you want to use any kind of provided automations, you must populate Email To field with either API name of the field you want to use (lookup, formula or other) or with hardcoded Id of a Contact or a Lead. No additional steps are required. See screenshot below, using the already mentioned formula field Contact_Formula__c.

NOTE: If you make any changes to the email to field or email section in document action, make sure to copy the updated document action code and paste into your related custom button.

How to create Lookup field to Lead or Contact object from base object:
Go to Setup > Object Manager > find related base object being used in document action > add New field > “Lookup field” type > relate to Contact or Lead object > label field as “X object primary contact” for example > make field visible on the base object page layout > populate the field on each record with a Primary Contact from Lead or Contact object and ensure that contact/lead has a valid email address.

Using Preview for Email in Document Action:
If you are setting email action to “preview” in document action, setting the email to field or email template is not required. Then when in preview of the email, you can manually populate related contact to send it too or type in physical email address.