function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Matt HewsonMatt Hewson 

Custom Button, Javascript, Email Templates and Merge Fields

Hi, I am trying to use a custom button for my account that calls an email template with merge fields and emails to the account owner requested information based on fields defined on the account.

{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
(function() {
sforce.connection.sessionId = "{!$Api.Session_ID}";

var message = new sforce.SingleEmailMessage();
message.replyTo = "noone@who.com";
message.ccAddresses = "noone@who.com";
message.targetObjectId = "{!Account.OwnerId}";
message.templateId = "xxxxxxxxxxxxx";
message.saveAsActivity = false;
var result = sforce.connection.sendEmail([message]);
  if(result[0].success == 'true') {
     alert("Email Sent");
  } else {
     alert("Something went wrong");
  }
alert(result);
}());

~~~~~ Email Template ~~~~~

Hi {!Account.OwnerFirstName},


Please can you provide the following information to Compliance for {!Account.Name}.

{!IF(!Account.Affidavit_Required__c="true", "", "Affidavit")}

{!IF(!Account.License_Required__c="true", "", "License")}

If you have any questions please contact the Compliance Manager.

Many Thanks,

Compliance

~~~~~ END ~~~~~

However, the emails come through blank where I expect to see merge field values and the IF statements don't work as values are not being passed. I have tried using whatId but it returned "whatId is an INVALID_ID_FIELD" error.

Please, can someone assist with getting to a suitable resolution?

Thanks in advance,

Matt