I'm trying to set up a JS button on a SFDC object record that sends an email to a recipient with a specific attachment from the Notes and Attachment related object. Would I theoretically be able to query an attachment from a specific file name and attach it to the email using a sforce.connection.sendEmail() method? See below for an example of the sendEmail method I got from this link.
sendEmail Example:
// single mail request
var singleRequest = new sforce.SingleEmailMessage();
singleRequest.replyTo = "[email protected]";
singleRequest.subject = "sent through ajax test driver";
singleRequest.plainTextBody = "this test went through ajax";
singleRequest.toAddresses = ["[email protected]"];
// mass mail request - need to get email template ID
var queryResponse = sforce.connection.query("select id from emailtemplate");
var templatedId = queryResponse.getArray("records")[0].Id;
var massRequest = new sforce.MassEmailMessage();
massRequest.targetObjectIds = [globalContact.id];
massRequest.replyTo = "[email protected]";
massRequest.subject = "sent through ajax test driver";
massRequest.templateId = templateId;
var sendMailRes = sforce.connection.sendEmail([singleRequest, massRequest]);
Apex
if you are willing to create aVisualforce
button instead. You can have it redirect right back to the detail page.