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
rbuchananrbuchanan 

need javascript sample for custom button to send an email to internal user, not lead or contact

Hi.  I've spent the last 2 hrs looking at some threads that have to do w/ this topic but could not find anything that looks like what i need to do.

 

I need a custom button on the lead detail page which, when clicked, will send an email to a co-worker and update the activites of that lead to show this email was sent.   I'd like to be able to provide the subject and body with the javascript on the fly, but if I have to use an email template, that's OK.    Everything I've tried that's already been posted has either given me compile errors when I click the button or an error message saying something about an invalid ID  (I tried to substitute my own user ID to receive the email).

 

Thanks for any and all help!

 

mill1012mill1012

I am looking for exactly the same thing.  Did you figure it out?

RudolfNiehausRudolfNiehaus

Hi,

 

I have done something similar. See if you can re-use the concepts. I have a custom button on a custom object that dynamically adds the attendees linked to the custom object to the recipient list and also if the user wants to add the default account team on the email cc recipient list.

 

 

 

{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")} 

var qrytemplateId = sforce.connection.query("select id,name from emailtemplate where Name like 'EventReport' Limit 1");
var templateIdrecords = qrytemplateId.getArray("records");

if (templateIdrecords.length > 0){ 
	var templateId = templateIdrecords[0].Id;
}
else{
	templateId = '00X200000013kCZ';
}

var Ccaddr = '';
var addTeam = confirm ("Add Default Client Team?");

if (addTeam){
	var resultTeam = sforce.connection.query("Select u.Id, u.Email From User u Where u.Id IN(Select a.UserId From AccountTeamMember a Where a.Account.Id =  '{!Call_Report__c.ClientId__c}')");

var recordsTeam = resultTeam.getArray("records");

if (recordsTeam.length > 0){ 
    for (t=0; t < recordsTeam.length; ++t){
        Ccaddr=Ccaddr + recordsTeam[t].Email + ';';
    }
}

}

var result = sforce.connection.query("Select Id, Email__c, Contact_Type__c, Status__c From Call_report_Attendees__c where Contact_Type__c = 'Internal' and Send_Email__c = 'Yes' and Call_report__c = '{!Call_Report__c.Id}'");

var records = result.getArray("records");

var AddToaddr = '';

if (records.length > 0){ 
    for (i=0; i < records.length; ++i){
        AddToaddr=AddToaddr + records[i].Email__c + ';';
     }
}

location.replace('/email/author/emailauthor.jsp?retURL=/{!Call_Report__c.Id}&template_id=' + templateId + '&p3_lkid={!Call_Report__c.Id}&rtype=003&p24=' + AddToaddr + '&p4=' + Ccaddr);