You need to sign in to do that
Don't have an account?

setWhatId on the sendmassemail - merge fields are empty
Hello,
I'm having an issue with sending an email. I'm using the following code and the email is indeed getting sent if I don't include the WhatIds but it is not getting the merge fields populated. If I include the WhatIds then I get an error message - "{faultcode:'soapenv:Client', faultstring:'Element {urn:partner.soap.sforce.com}WhatIds invalid at this location', }:result ="
Any help would be greatly appreciated.
<html>
<head>
<script src="/soap/ajax/10.0/connection.js" type="text/javascript"></script>
<script>
alert("Starting script");
var contactId = "{!Contact.Id}";
var contractId = "{!Contract.Id}";
alert("ContactId: " + contactId);
alert("ContractId: " + contractId);
function sendEmail() {
alert("Starting sendEmail function");
var result = "";
try {
alert("Starting Try");
var mass = new sforce.MassEmailMessage();
mass.replyTo = "rleblanc@syberworks.com";
alert("mass.replyTo: " + mass.replyTo);
mass.subject = "Mass Email from SF!";
alert("mass.subject: " + mass.subject);
var a = new Array(1);
a[0] = contactId;
alert("Contact ID - a[0]: " + a[0]);
mass.targetObjectIds = "0035000000ZxRr7";
alert("Mass targetObjectIds: " + mass.targetObjectIds);
mass.saveAsActivity = false;
mass.WhatIds = contractId;
alert("mass.WhatIds: " + mass.WhatIds);
mass.templateId = "00X50000000xsVKEAY";
alert("Mass.templateId: " + mass.templateId);
var sendMailRes = sforce.connection.sendEmail([mass]);
output.innerHTML = "Email sent! " + "result: " + result;
} catch(error) {
output.innerHTML = error + ":result = " + result;
}
}
</script>
<body onload="sendEmail()">
<div id="output"></div>
</body>
</html>
I got this code from a previous post and modified it some but if I can get it to work will likely continue to modify it.
Thanks!
Renee
Does anyone have any ideas here? I really can't find anything useful in the help about this.
I noticed that my code ended up with some silly smiley faces in it - hopefully this will be a cleaner copy.
<html> <head> <script src="/soap/ajax/10.0/connection.js" type="text/javascript"></script> <script> alert("Starting script"); var contractId = "{!Contract.Id}"; alert("ContractId: " + contractId); function sendEmail() { alert("Starting sendEmail function"); var result = ""; try { alert("Starting Try"); var mass = new sforce.MassEmailMessage(); mass.replyTo = "rleblanc@syberworks.com"; alert("mass.replyTo: " + mass.replyTo); mass.subject = "Mass Email from SF!"; alert("mass.subject: " + mass.subject); mass.targetObjectIds = "0035000000ZxRr7"; alert("Mass targetObjectIds: " + mass.targetObjectIds); var a = new Array(1); a[0]=contractId; a[1]=contractId; mass.WhatIds = a[1]; alert("mass.WhatIds: " + mass.WhatIds); mass.saveAsActivity = false; //alert("mass.WhatIds: " + mass.WhatIds); mass.templateId = "00X50000000xsVKEAY"; alert("Mass.templateId: " + mass.templateId); var sendMailRes = sforce.connection.sendEmail([mass]); output.innerHTML = "Email sent! " + "result: " + result; } catch(error) { output.innerHTML = error + ":result = " + result; } } </script> <body onload="sendEmail()"> <div id="output"></div> </body> </html>
And the error message I'm getting is
{faultcode:'soapenv:Client', faultstring:'Element {urn:partner.soap.sforce.com}WhatIds invalid at this location', }:result =
Thanks for any help!
Renee
This line from the Web Services documentation might help:
If you specify whatIds, specify one for each targetObjectId; otherwise, you will receive an INVALID_ID_FIELD error
http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_sendemail.htm
Cheers,
-Philip