You need to sign in to do that
Don't have an account?
Problem with whatId using template in SingleEmailMessage
Hi,
We've created an email template which references fields of a custom object named Intervention.
Intervention object has a detail button that must send email using that template. We are receiving the error "Invalid whatId" when we try to send email.
In javascript implemented in the button we have assigned the field Name (standard ID field ) of Intervention to property whatId of SingleEmailMessage.
Can someone help us what is the problem with whatId?
A excerpt of our code below:
.....
var req = new sforce.SingleEmailMessage();
req.orgWideEmailAddressId = [orgWideEmailAddresstId ];
req.ccAddresses =[ ccSupervisao, ccSuporte ];
//Sender will receive a copy of the mass e-mail sent
req.bccSender=true;
req.emailPriority='High';
req.replyTo=targetAddress;
req.targetObjectId=targetObjectId;
req.saveAsActivity=false;
var name = {!Intervention__c.Name};
req.whatId = name;
// Query template ID
var templateName = "{!Intervention__c.Modelo_de_Email__c}";
var queryEmailTemplate = sforce.connection.query("select Id from EmailTemplate where name ='" + templateName + "'");
var templateId = queryEmailTemplate.getArray("records")[0].Id;
req.templateId=templateId;
.....
Many thanks,
Ana
I think you want the whatID to be the record ID, not the record name. Try
var name = {!Intervention__c.Id};