+ Start a Discussion
NilaNila 

Email through s-Control

Hi There,
I am trying to create s-control for email . I can send single email without template. If I try to send email with template its not worikng.
Any idea?
code looks like
 
var user = sforce.connection.getUserInfo().userEmail;
var queryResponse = sforce.connection.query("select id from emailtemplate where name = 'test'");
var records = queryResponse.getArray("records");
var templatedId = records[0];
var request = new sforce.MassEmailMessage();
massRequest.saveAsActivity = false;
request .templateId = templatedId ;
var ids = new Array(1);
  ids[0] = "{!Contact.Id}";
massRequest.targetObjectIds = ids;
massRequest.subject = "sent through ajax test driver";
massRequest.replyTo = user;
var sendMailRes = sforce.connection.sendEmail([massRequest]);
Error is
faultcode 'soapenv:Client', faultstring:'Unexpected element {urn:partner.soap.sforce.com}type during simple type deserialization
Rasmus MenckeRasmus Mencke
Hi,
 
I made a couple of small changes to the code, the code below is working for me.
 
Make all the references to the MassEmailMessage to massRequest, you have both "request" and "massRequest" references.
 
To reference a template you will need to reference the specific template id, see the code I have pasted below, and make sure the template is active.
 
The last alert will show you either what errors you are getting or if the call was a success. You can use that for debugging.
 
var user = sforce.connection.getUserInfo().userEmail;
var queryResponse = sforce.connection.query("select id from emailtemplate where name = 'test'");
var records = queryResponse.getArray("records");
var templatedId = records[0];
var massRequest = new sforce.MassEmailMessage();
massRequest.saveAsActivity = false;
massRequest.templateId = templatedId.Id;
var ids = new Array(1);
ids[0] = "{!Contact.Id}";
massRequest.targetObjectIds = ids;
massRequest.subject = "sent through ajax test driver";
massRequest.replyTo = user;
var sendMailRes = sforce.connection.sendEmail([massRequest]);
alert(sendMailRes);
NilaNila
Thank you very much,
Its working for me as well..