{"id":187788,"date":"2019-08-02T13:12:52","date_gmt":"2019-08-02T13:12:52","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=187788"},"modified":"2026-02-13T13:54:05","modified_gmt":"2026-02-13T13:54:05","slug":"send-merge-field-of-custom-object-through-email-template-using-apex","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/send-merge-field-of-custom-object-through-email-template-using-apex\/","title":{"rendered":"How Send an Email Template with Custom Object Merge Fields?"},"content":{"rendered":"\n<p>Salesforce email templates work beautifully until you use them for custom object email merge fields.<\/p>\n\n\n\n<p>And the problem isn&#8217;t with your code or template. It&#8217;s Salesforce&#8217;s architecture.<\/p>\n\n\n\n<p>They have a specific requirement that they only play nice with Contact, Lead, and User objects, but not with custom objects.<\/p>\n\n\n\n<p>If you&#8217;re facing this same problem, follow this guide to send email templates with custom object data.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why doesn\u2019t Merge Fields from Custom Objects work?<\/h2>\n\n\n\n<p>Salesforce email templates are tightly coupled to TargetObjectId and WhatId relationships. These determine who receives the email, and it only accepts IDs from standard objects like:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Contact<\/li>\n\n\n\n<li>Lead<\/li>\n\n\n\n<li>User<\/li>\n\n\n\n<li>Opportunity<\/li>\n\n\n\n<li>Case<\/li>\n<\/ul>\n\n\n\n<p>So when you try to merge fields from custom objects in an email template, Salesforce doesn&#8217;t know what to do. That&#8217;s why it renders empty even though the records exist.<\/p>\n\n\n\n<p>To make merge fields work, we have to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Create a relationship bridge<\/li>\n\n\n\n<li>Create records in custom objects<\/li>\n\n\n\n<li>Build Your Email Template with Custom Object Merge Field<\/li>\n\n\n\n<li>Create an Apex Class to <a href=\"https:\/\/webkul.com\/blog\/sending-email-apex\/\">send an email<\/a><\/li>\n<\/ul>\n\n\n\n<p>Once those three pieces align, Salesforce will render the merge data normally.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Create a Custom Object Relationships<\/h2>\n\n\n\n<p>First, you need a custom object. For this example, I&#8217;ll create one called Training_Registration__c that tracks employee training sessions.<\/p>\n\n\n\n<p>Go to <strong>Setup \u2192 Object Manager \u2192 Create \u2192 Custom Object<\/strong><\/p>\n\n\n\n<p>Name it whatever makes sense for your business case. Next, the most crucial step is where you need ot add a Lookup field that points to Contact, Lead, or User. Let&#8217;s see how you can add a Lookup Relationship:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Click into your custom object<\/li>\n\n\n\n<li>Navigate to Fields &amp; Relationships<\/li>\n\n\n\n<li>Click <strong>New<\/strong><\/li>\n\n\n\n<li>Select <strong>Lookup Relationship<\/strong><\/li>\n\n\n\n<li>Choose <strong>Contact<\/strong> as the related object<\/li>\n\n\n\n<li>Name it something like ContactRelationship__c<\/li>\n<\/ol>\n\n\n\n<p>Now, here this tells Salesforce that your custom object record is connected to the contact record.<\/p>\n\n\n\n<p><strong>Important note:<\/strong> You can create up to 25 Lookup fields and 2 Master-Detail relationships on a single custom object.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"1833\" height=\"776\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/07\/23083722\/test3.png\" alt=\"custom object merge fields \" class=\"wp-image-188120\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/07\/23083722\/test3.png 1833w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/07\/23083722\/test3.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/07\/23083722\/test3.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/07\/23083722\/test3.png 768w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/07\/23083722\/test3.png 1200w\" sizes=\"(max-width: 1833px) 100vw, 1833px\" loading=\"lazy\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Create Records of Custom Object with Sample Data<\/h2>\n\n\n\n<p>Further, add a test record to your custom object and fill in the relationship field with an actual Contact.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"1856\" height=\"956\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/07\/23083830\/Joe-Smith-_-Salesforce.jpg\" alt=\"record in custom object\" class=\"wp-image-188122\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/07\/23083830\/Joe-Smith-_-Salesforce.jpg 1856w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/07\/23083830\/Joe-Smith-_-Salesforce.jpg 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/07\/23083830\/Joe-Smith-_-Salesforce.jpg 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/07\/23083830\/Joe-Smith-_-Salesforce.jpg 768w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/07\/23083830\/Joe-Smith-_-Salesforce.jpg 1200w\" sizes=\"(max-width: 1856px) 100vw, 1856px\" loading=\"lazy\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Build Your Email Template with Custom Object Merge Fields<\/h2>\n\n\n\n<p>This is where things get interesting. Head over to <strong>Setup \u2192 Email \u2192 Classic Email Templates<\/strong>.<\/p>\n\n\n\n<p>Click <strong>New Template<\/strong> and create a Text or Custom (HTML) template.<\/p>\n\n\n\n<p>Go to <strong>Setup \u2192 Email \u2192 Classic Email Templates<\/strong>. Click <strong>New Template<\/strong> and create a Text or Custom (HTML) template.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"960\" height=\"815\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/07\/23083955\/test2.png\" alt=\"custom object merge fields \" class=\"wp-image-188123\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/07\/23083955\/test2.png 960w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/07\/23083955\/test2.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/07\/23083955\/test2.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/07\/23083955\/test2.png 768w\" sizes=\"(max-width: 960px) 100vw, 960px\" loading=\"lazy\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">4. Create an Apex Class to send an email<\/h2>\n\n\n\n<p>Here we are creating an Apex class, CustomObjectEmailExample, which will be called from a  Visualforce page. You can utilize it according to your business scenario.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"> CustomObjectEmailExample Class<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\"> \/**\n  * Webkul Software.\n  *\n  * @category  Webkul\n  * @author    Webkul\n  * @copyright Copyright (c) 2010-2016 Webkul Software Private Limited (https:\/\/webkul.com)\n  * @license   https:\/\/store.webkul.com\/license.html\n  *\/\npublic class CustomObjectEmailExample {\n\tpublic PageReference sendingMail() {\t\t\n        Messaging.SingleEmailMessage mail =  new \n        Messaging.SingleEmailMessage();\/\/ create instance of \n         SingleEmailMessage class\n\tString&#091;] sendingToBccAdd = new String&#091;] \n        {&#039;XXXXXXXXX@webkul.com&#039;}; \/\/ Add email addresses to blind \n        carbon copy (BCC) addresses. The maximum allowed is 25.\n       mail.setBccAddresses(sendingToBccAdd);\n       String&#091;] sendingTocAdd = new String&#091;]{&#039;XXXXXXXXX@webkul.com&#039;};  \n       \/\/ add addresses to carbon copy(CC). The maximum allowed is 25.\n\tmail.setCcAddresses(sendingTocAdd);\n        mail.setReplyTo(userinfo.getUserEmail());\n        mail.setTargetObjectId(&#039;xxxxxxxxxxx&#039;);\/\/ This is the ID of rel \n        mail.setSaveAsActivity(false);\n        mail.setWhatId(&#039;XXXXXXXXXXXXXXXXX&#039;);\/\/ This is the record ID\n        mail.setTemplateId(template);\/\/ This is template ID\n        mail.setSenderDisplayName(userinfo.getname());\n        Messaging.sendEmail(mail);\n\treturn null;\n\t}\n}<\/pre>\n\n\n\n<p><strong>Visualforce Page:<\/strong> sendEmail Page<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\"> \/**\n  * Webkul Software.\n  *\n  * @category  Webkul\n  * @author    Webkul\n  * @copyright Copyright (c) 2010-2016 Webkul Software Private Limited (https:\/\/webkul.com)\n  * @license   https:\/\/store.webkul.com\/license.html\n  *\/\n&lt;apex:page controller=&quot;CustomObjectEmailExample&quot;&gt;\n  &lt;apex:form &gt;\n    &lt;apex:commandButton value=&quot;Send Email&quot; action=&quot;{!sendingMail}&quot;\/&gt;\n  &lt;\/apex:form&gt;\n&lt;\/apex:page&gt;<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">5. The Output of Example<\/h2>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/07\/23085456\/test1-png-1854%C3%971000.jpg\" alt=\"image unavailable\" class=\"wp-image-188139\" loading=\"lazy\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Final Thoughts<\/h2>\n\n\n\n<p>It&#8217;s not Salesforce&#8217;s fault if the email template merge field is not working. It&#8217;s just how Salesforce&#8217;s email engine is designed.<\/p>\n\n\n\n<p>And once the relationship chain is correct, the system behaves according to you.<\/p>\n\n\n\n<p>The steps could work for any custom objects you make. Whether you want to send invoices, personalized messages, or anything else, the pattern stays the same.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Support<\/h2>\n\n\n\n<p>Need help implementing this in your org? Our<a href=\"https:\/\/webkul.com\/salesforce-consulting-services\/\"> Salesforce consulting team<\/a> has built email automation for hundreds of companies across every industry imaginable. Or<\/p>\n\n\n\n<p><a href=\"https:\/\/webkul.uvdesk.com\/en\/customer\/create-ticket\/\">Raise a ticket<\/a> to let us know about your custom requirements.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>salesforce custom object email template<\/p>\n","protected":false},"author":45,"featured_media":188172,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1889,1887,2166,5059,1,4110],"tags":[1884,9334,5184,9336,5186,9335,2490],"class_list":["post-187788","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-apex","category-salesforce","category-salesforce-connector","category-shopify-salesforce-connector","category-uncategorized","category-wedgecommerce-salesforce-connector","tag-apex","tag-custom-object","tag-email-apex","tag-object-relationship-field","tag-salesforce-apex-email","tag-salesforce-email-teamplate","tag-salesforce-event-reminder"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How Send an Email Template with Custom Object Merge Fields?<\/title>\n<meta name=\"description\" content=\"Send Salesforce email templates with merge fields from a custom object using Apex. Includes setup, code sample, and best practices.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/send-merge-field-of-custom-object-through-email-template-using-apex\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How Send an Email Template with Custom Object Merge Fields?\" \/>\n<meta property=\"og:description\" content=\"Send Salesforce email templates with merge fields from a custom object using Apex. Includes setup, code sample, and best practices.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/send-merge-field-of-custom-object-through-email-template-using-apex\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/kailashchandradhoulakhandi\" \/>\n<meta property=\"article:published_time\" content=\"2019-08-02T13:12:52+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-02-13T13:54:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/07\/23104618\/cropped-3-7.png\" \/>\n\t<meta property=\"og:image:width\" content=\"632\" \/>\n\t<meta property=\"og:image:height\" content=\"356\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Kailash Chandra\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kailash Chandra\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/send-merge-field-of-custom-object-through-email-template-using-apex\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/send-merge-field-of-custom-object-through-email-template-using-apex\/\"},\"author\":{\"name\":\"Kailash Chandra\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/07afa2c65f134699062871eaf4a83f02\"},\"headline\":\"How Send an Email Template with Custom Object Merge Fields?\",\"datePublished\":\"2019-08-02T13:12:52+00:00\",\"dateModified\":\"2026-02-13T13:54:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/send-merge-field-of-custom-object-through-email-template-using-apex\/\"},\"wordCount\":547,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/send-merge-field-of-custom-object-through-email-template-using-apex\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/07\/23104618\/cropped-3-7.png\",\"keywords\":[\"Apex\",\"custom object\",\"Email Apex\",\"object relationship field\",\"Salesforce APEX Email\",\"salesforce email teamplate\",\"Salesforce Event Reminder\"],\"articleSection\":{\"0\":\"Apex\",\"1\":\"Salesforce\",\"2\":\"Salesforce Connector\",\"3\":\"Shopify Salesforce Connector\",\"5\":\"Wedgecommerce\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/send-merge-field-of-custom-object-through-email-template-using-apex\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/send-merge-field-of-custom-object-through-email-template-using-apex\/\",\"url\":\"https:\/\/webkul.com\/blog\/send-merge-field-of-custom-object-through-email-template-using-apex\/\",\"name\":\"How Send an Email Template with Custom Object Merge Fields?\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/send-merge-field-of-custom-object-through-email-template-using-apex\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/send-merge-field-of-custom-object-through-email-template-using-apex\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/07\/23104618\/cropped-3-7.png\",\"datePublished\":\"2019-08-02T13:12:52+00:00\",\"dateModified\":\"2026-02-13T13:54:05+00:00\",\"description\":\"Send Salesforce email templates with merge fields from a custom object using Apex. Includes setup, code sample, and best practices.\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/send-merge-field-of-custom-object-through-email-template-using-apex\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/send-merge-field-of-custom-object-through-email-template-using-apex\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/send-merge-field-of-custom-object-through-email-template-using-apex\/#primaryimage\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/07\/23104618\/cropped-3-7.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/07\/23104618\/cropped-3-7.png\",\"width\":632,\"height\":356,\"caption\":\"cropped-3-7\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/send-merge-field-of-custom-object-through-email-template-using-apex\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How Send an Email Template with Custom Object Merge Fields?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/07afa2c65f134699062871eaf4a83f02\",\"name\":\"Kailash Chandra\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/ea77fb0ff5d7b6f68e2a9186ef37f39b3698bb628b47c1c40f9c31704b910158?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/ea77fb0ff5d7b6f68e2a9186ef37f39b3698bb628b47c1c40f9c31704b910158?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Kailash Chandra\"},\"description\":\"Kailash Chandra is a 9x Salesforce Certified professional with experience in Health Cloud, Heroku and Agile Jenkins. He specialises in AppExchange application development, Commerce Cloud, and PMD, providing innovative solutions that improve business operations and drive strategic growth inside the Salesforce ecosystem.\",\"sameAs\":[\"https:\/\/www.facebook.com\/kailashchandradhoulakhandi\"],\"url\":\"https:\/\/webkul.com\/blog\/author\/kailash\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How Send an Email Template with Custom Object Merge Fields?","description":"Send Salesforce email templates with merge fields from a custom object using Apex. Includes setup, code sample, and best practices.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/send-merge-field-of-custom-object-through-email-template-using-apex\/","og_locale":"en_US","og_type":"article","og_title":"How Send an Email Template with Custom Object Merge Fields?","og_description":"Send Salesforce email templates with merge fields from a custom object using Apex. Includes setup, code sample, and best practices.","og_url":"https:\/\/webkul.com\/blog\/send-merge-field-of-custom-object-through-email-template-using-apex\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_author":"https:\/\/www.facebook.com\/kailashchandradhoulakhandi","article_published_time":"2019-08-02T13:12:52+00:00","article_modified_time":"2026-02-13T13:54:05+00:00","og_image":[{"width":632,"height":356,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/07\/23104618\/cropped-3-7.png","type":"image\/png"}],"author":"Kailash Chandra","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Kailash Chandra","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/send-merge-field-of-custom-object-through-email-template-using-apex\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/send-merge-field-of-custom-object-through-email-template-using-apex\/"},"author":{"name":"Kailash Chandra","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/07afa2c65f134699062871eaf4a83f02"},"headline":"How Send an Email Template with Custom Object Merge Fields?","datePublished":"2019-08-02T13:12:52+00:00","dateModified":"2026-02-13T13:54:05+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/send-merge-field-of-custom-object-through-email-template-using-apex\/"},"wordCount":547,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/send-merge-field-of-custom-object-through-email-template-using-apex\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/07\/23104618\/cropped-3-7.png","keywords":["Apex","custom object","Email Apex","object relationship field","Salesforce APEX Email","salesforce email teamplate","Salesforce Event Reminder"],"articleSection":{"0":"Apex","1":"Salesforce","2":"Salesforce Connector","3":"Shopify Salesforce Connector","5":"Wedgecommerce"},"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/send-merge-field-of-custom-object-through-email-template-using-apex\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/send-merge-field-of-custom-object-through-email-template-using-apex\/","url":"https:\/\/webkul.com\/blog\/send-merge-field-of-custom-object-through-email-template-using-apex\/","name":"How Send an Email Template with Custom Object Merge Fields?","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/send-merge-field-of-custom-object-through-email-template-using-apex\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/send-merge-field-of-custom-object-through-email-template-using-apex\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/07\/23104618\/cropped-3-7.png","datePublished":"2019-08-02T13:12:52+00:00","dateModified":"2026-02-13T13:54:05+00:00","description":"Send Salesforce email templates with merge fields from a custom object using Apex. Includes setup, code sample, and best practices.","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/send-merge-field-of-custom-object-through-email-template-using-apex\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/send-merge-field-of-custom-object-through-email-template-using-apex\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/send-merge-field-of-custom-object-through-email-template-using-apex\/#primaryimage","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/07\/23104618\/cropped-3-7.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/07\/23104618\/cropped-3-7.png","width":632,"height":356,"caption":"cropped-3-7"},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/send-merge-field-of-custom-object-through-email-template-using-apex\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How Send an Email Template with Custom Object Merge Fields?"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/07afa2c65f134699062871eaf4a83f02","name":"Kailash Chandra","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/ea77fb0ff5d7b6f68e2a9186ef37f39b3698bb628b47c1c40f9c31704b910158?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ea77fb0ff5d7b6f68e2a9186ef37f39b3698bb628b47c1c40f9c31704b910158?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Kailash Chandra"},"description":"Kailash Chandra is a 9x Salesforce Certified professional with experience in Health Cloud, Heroku and Agile Jenkins. He specialises in AppExchange application development, Commerce Cloud, and PMD, providing innovative solutions that improve business operations and drive strategic growth inside the Salesforce ecosystem.","sameAs":["https:\/\/www.facebook.com\/kailashchandradhoulakhandi"],"url":"https:\/\/webkul.com\/blog\/author\/kailash\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/187788","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/45"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=187788"}],"version-history":[{"count":29,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/187788\/revisions"}],"predecessor-version":[{"id":526503,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/187788\/revisions\/526503"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media\/188172"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=187788"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=187788"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=187788"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}