You need to sign in to do that
Don't have an account?
Eric Santiago
Sending email to contact from Scontrol
I'm writing a function to send an email to a contact referenced in a custom object. I was trying to use the SendEmail call defined in the API and the 9.0 Ajax kit.
Code:
Code:
function sendEmail() {Unfortunately, when I run this I get the error "An error has occurred: TypeError: sendResult.SendEmailError has no properties" So obviously the SendEmail call is unsuccessfull in creating a SendEmailResult object for me to get an error from. The sforce.debug log just reads Null. Not much to help me troubleshoot. Any one have some suggestions?
var message = new sforce.SObject("SingleEmailMessage");
//message.set("CcAddresses", "me@ml4t.org");
message.set("BccSender",true);
//message.set("EmailPriority",EmailPriority.High);
message.set("ReplyTo", "{!$User.Email}");
message.set("SaveAsActivity", true);
message.set("Subject", "This is how you use the sendEmail call.");
//We can also just use an id for an implicit to address
message.set("TargetObjectId","0033000000Ew25A");
message.set("UseSignature",true);
message.set("PlainTextBody", "This is the body of the message.");
try
{
var sendResult = new sforce.SObject("SendEmailResult");
sendResult = sforce.connection.sendEmail(message);
}
catch(error)
{
//sforce.debug.log(error.faultcode);
//sforce.debug.log(error.faultstring);
errorMsg = sendResult.SendEmailError.Message;
txt="There was an error sending an email.\n\n";
txt+="Error description: " + errorMsg + "\n\n";
txt+="Click OK to continue.\n\n";
alert(txt);
}
}
I am trying to use the MassEmailMessage and I get the following message back from the sendEmail method:
Code:
I am at a loss at to what this means. I am sending an array of messages with the following (slightly edited):
Control transfers to the emailError function with the error text I mentioned above.
Code:
should be
Code:
sendEmail() will construct the return object, also this is not a valid SObject() anyway, it's got it's own type, in general you never have to construct a new result object , the toolkit does that for you
should look more like this ( i think, did not test)
Message Edited by Ron Hess on 04-01-2007 12:31 PM
you can see that it allows fields from both single and mass to be passed into the call to send email
Code:
Thank you for your help Ron, you solved my issues.
I don't know how I missed the code sample from the APEX docs.
Ken
Now that I've got things working I did have some questions around mass email limits. The documentation says an organization has a limit of 1,000 mass emails per day. Is there a way to determine the current count programatically? I didn't notice it in the merge fields available.