2

I have created custom button to send visualforce page url with opportunity id in opportunity detail page. How can i send URl like 'https://c.ap1.visual.force.com/apex/QuoteOrderForm?id=0069000000DOa0Q' with creating controller or page.

3
  • Did you want to say 'without creating controller or page' above? If so, the answer is no. There is no Email API accessible from JavaScript to send an email. At the very least you will need a small bit of Apex code to use the Apex Email API. Also with Apex you can attach HTML/PDF output from your QuoteOrderForm page as an attachment to the email via this API. If you still want to call all this via JavaScript you can wrap it all in a Apex Web Service and call that from JavaScript. Will this type of solution help? Sep 30, 2013 at 7:11
  • Nope, i want to send email without using any apex code
    – Reddy
    Sep 30, 2013 at 10:10
  • The Salesforce Partner API (a SOAP API) has a sendEmail feature, it's not something I've used in anger (more of a VF/Apex guy), but the Salesforce AJAX Toolkit does expose this API to JavaScript, I think my answer gives you the info you need to proceed. Sep 30, 2013 at 12:14

1 Answer 1

7

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.

// 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]);

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .