I ran this code and result is not quite what you think.
If you alert
the whole result object, you get this:
{errors:{message:'Only Users, Contact, Lead or Person objects are allowed for targetObjectId : a0SK000000FtD7J.', statusCode:'INVALID_TYPE_FOR_OPERATION', targetObjectId:null, }, success:'false', }
Your code needs to look like this to actually work:
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
(function() {
sforce.connection.sessionId = "{!$Api.Session_ID}";
var message = new sforce.SingleEmailMessage();
message.replyTo = "rapsac@gmail.com";
message.targetObjectId = "005K0000002butj";
message.templateId = "00XK0000000QsbW";
message.saveAsActivity = false;
var result = sforce.connection.sendEmail([message]);
if(result[0].success == 'true') {
alert("I sent the email as you requested, master.");
} else {
alert("I had a booboo.");
}
alert(result);
}());
There were several other errors too - the key is to output the whole error in an alert so you can debug it.
As you can see, the targetObjectId
is the user that the email is going to, not the object that the template refers to.
Also, saveAsActivity
needs to be false to send to an internal user.
This is probably going to take quite a bit of work to get going, but hopefully you are now on the right track.
Best Answer
Take a look at the Salesforce AJAX Toolkit documented here. It is a JavaScript wrapper library around the Saleforce Partner API (a SOAP API). Which does provide an operation sendEmail. There is a JavaScript example of using the 'sendEmail' operation via the AJAX Toolkit here.
EMAIL TEMPLATE NOTE: The Salesforce sample above references an Email Template, you can create these just as you do Visualforce pages. Note that in your case you'll likely want to query for a specific one. Also if you wanted to share your Quote Visualforce page into such a a template, I've used Visualforce Components in the past to share my Visualforce markup between a VF page and a VF Email Template. You can of course just copy and paste into the VF Email Template, depending on how often your page changes this might be easier.