function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
prhannonprhannon 

Javascript Button - Wrong Fields/Placement?

Hi Everyone,

I'm not a developer, so sorry if this is a little simple...I'm trying to create a button that can be clicked in a case record to send an email to the contact slotted in the case's Case ME field (custom Contact lookup field). The body of the email contains merge fields.

I'm not a developer, so am just guessing & testing my way through this (see code at bottom). I've run into a couple of roadblocks:

- I have put myself in the test record as Case ME. When I hit the button I don't get an error message, and the API call email comes in, but I do not receive an email.
- When I pull in the actual text I would like to use (vs. "test") I get an error message stating "unterminated string literal"

I've played around with this some with no success. Could anyone steer me in the right direction?

Thanks!
---------------
{!REQUIRESCRIPT("/soap/ajax/9.0/connection.js")}

// single mail request
var singleRequest = new sforce.SingleEmailMessage();
singleRequest.replyTo = "support@journalexperts.com";
singleRequest.subject = "sent through ajax test driver";

singleRequest.plainTextBody = "this test went through ajax";
singleRequest.toAddresses = "{!Case.OwnerId}";

// mass mail request - need to get email template ID
var massRequest = new sforce.MassEmailMessage();
massRequest.targetObjectIds = ['0035000001N68EU'];
massRequest.replyTo = "support@journalexperts.com";
massRequest.subject = "sent through ajax test driver";

massRequest.plainTextBody = "*** NEW CASE ASSIGNMENT NOTIFICATION ***
The following case has been assigned to you.

Company: {!Organization.Name}
Contact Name: {!Contact.Name}
Case #: {!Case.Id} {!Case.CaseNumber}
Contact Email: {!Case.SuppliedEmail}

Submission ID: {!Case.Sub_ID__c}
Link to Submission: {!Case.Link_to_Sub__c}
Submission Type: {!Case.Type}

Subject: {!Case.Subject}
Description: {!Case.Description}

Click on the link to access the case: {!Case.Link}"

 

// send the email
var sendMailRes = sforce.connection.sendEmail([singleRequest, massRequest]);